JQuery switch value: "Do not exclude syntax error, unrecognized expression"

I try to get the switch value with $("input[@name=login]") , but I get the error "Unexplored syntax, unrecognized expression".

See http://jsfiddle.net/fwnUm/ and here is the full code:

 <!-- Radio buttons to choose signin/register --> <fieldset data-role="controlgroup" data-theme="z" data-type="horizontal" > <input type="radio" name="login" id="radio-signin" value="signin" checked="checked" /> <label for="radio-signin">Signin</label> <input type="radio" name="login" id="radio-register" value="register" /> <label for="radio-register">Register</label> </fieldset> $(document).ready(function() { $("input[@name=login]").change(function(){ alert($("input[@name=login]:checked").val()); }); }); 
+4
source share
6 answers

XPath-like attribute selectors were removed in jQuery 1.3. (We are now on jQuery 1.6.)

Just delete @ :

 $("input[name='login']").change(function(){ alert($("input[name='login']:checked").val()); }); 

Note that quotes are also needed.

See the API link for an attribute equal to a selector.

+10
source

Remove @ . $("input[name=login]")

You probably also want to use this in your callback:

 $(document).ready(function() { $("input[name=login]").change(function(){ alert($(this).val()); }); }); 
+1
source

Just $("input[name=login]") works for me. I've never seen @ used in this context before, should it do something?

0
source

Lose the @ character in the selector.

0
source

Remove the @ character from your selectors as it does not exist in jQuery 1.5.2.

Here is your Fiddle updated .

0
source

You need quotes around the attribute value, 'login'. Also, I don't think you need the @ character:

  $("input[name='login']").change(function(){ alert($("input[name='login']:checked").val()); }); 
0
source

All Articles