How to get the key of a multi diamentional select box using jQuery -


i'm working on jquery custom validation of multidimensional select box. i'm trying access name of multidimensional select box element:

 <select id="start_time_195" class="myclass" name="start_time[195]"> 

using following code snippet:

$.validator.addmethod("my_method", function(value, element) {     console.log(element.name); }, "this text displayed validation message."); 

the console output start_time[195]

but want key 195 out of element name. there direct way value?

the alternate way think use .split() function, bit lengthy process.

thank help.

  1. add in data @rory mccrossan suggested. can add id in attribute data-id = 195

    $(this).attr('data-id'); 
  2. if dont't want fetch id

    var id =$(this).attr('id'); getid = id.split("_"); getid[2]  // value 

Comments