1

I have many elements that are structured to get them in array like mapping on server side.

<input type="CHECKBOX" id="478" value="1" name="data[GroupInfo][student][478]" onclick="return updateValues('478')">
<input type="CHECKBOX" id="490" value="1" name="data[GroupInfo][student][490]" onclick="return updateValues('490')">

<input type="CHECKBOX" id="478" value="1" name="data[ClassInfo][student][478]" onclick="return updateValues('478')">
<input type="CHECKBOX" id="490" value="1" name="data[ClassInfo][student][490]" onclick="return updateValues('490')">

so on... Now, I want to select them using their name attribute like

$("[name^=data[ClassInfo][student]]");

but this won't work I tried to escape barckets to.

$("[name^=data\[ClassInfo\]\[student\]]");

but no luck;

I want to select them using name attribute.

lokeshjain2008
  • 1,879
  • 1
  • 22
  • 36

4 Answers4

3

Just wrap the attribute value in ""

$('input[name^="data[ClassInfo][student]"]')

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

Try:

// For exact element
    $('input[name=data[GroupInfo][student][478]]');

Or

// For list of elements
    $('input[name^=data[GroupInfo][student]]');

You can see more here

Community
  • 1
  • 1
Ringo
  • 3,795
  • 3
  • 22
  • 37
0

Try this:

$("[name^='data[ClassInfo][student]']");//Wrap in the single quotes
Somnath Kharat
  • 3,570
  • 2
  • 27
  • 51
0
$('input[name*="data[ClassInfo][student]"]') // matches those that contain 'data[ClassInfo][student]'
aditya mukkawar
  • 166
  • 1
  • 5