Green
Green

Reputation: 390

JQuery delegate not working for certain inputs

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

Upvotes: 0

Views: 1866

Answers (1)

Boris Delormas
Boris Delormas

Reputation: 2549

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

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

Upvotes: 2

Related Questions