0

Why below code call error when i use sizzle:

var $myInput="#myForm input";

$($myInput+":checked").click(function(){
  ....
});

the $($myInput+":checked") selector return "[object Object] :checked". But when I simply use the variable content like $("#myForm input:checked") work as carefully.

Thanks

mhdrad
  • 330
  • 3
  • 15

1 Answers1

1

$myInput seems to be an object in your code, but is a string in your example code.

If you want to filter $myInput and only apply this event handler to :checked inputs, use something like this:

$myInput.filter(':checked').click(function() {
  // ...
});

Note that this handler is bound to elements that exist when $myInput was created, so this won't account for elements created later in time.

Blender
  • 289,723
  • 53
  • 439
  • 496