tags:

views:

43

answers:

1

I'm tring to use JQuery to automatically sum inputs in a table where rows are added dynamically. $().delegate and $().live do not seem to work if the selector contains an input with a name with [ ]. The same selector works with bind.

Here is a sample code :

<div id="area">
  <input name="x[]"/>
  <input name="x[]"/>
  <input name="x[]"/>
  <input name="x[]"/>
</div>

$("#area").delegate("input[name='x\\[\\]']", 'change', function () {
  console.log($(this).val());
});

Any suggestions on how to fix this ?

Sample code

+1  A: 

Worked for me using this : http://jsbin.com/eyoro3/3/edit

$("#area").delegate("input[name='x\[\]']", 'change', function () {
  console.log($(this).val());
});
Kaaviar
Apparently, [ ] shouldn't be escaped, unlike for bind. "input[name='x[]']" works too. Thanks !
Green