I'm trying to get the value of a radio button with $("input[@name=login]")
, but am getting "Uncaught Syntax error, unrecognized expression".
See / and here's the code in full:
<!-- 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());
});
});
I'm trying to get the value of a radio button with $("input[@name=login]")
, but am getting "Uncaught Syntax error, unrecognized expression".
See http://jsfiddle/fwnUm/ and here's the code in full:
<!-- 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());
});
});
Share
Improve this question
asked May 6, 2011 at 13:58
simonsimon
6,11713 gold badges32 silver badges28 bronze badges
6 Answers
Reset to default 10XPath-like attribute selectors were removed in jQuery 1.3. (We're now on jQuery 1.6.)
Just remove the @
:
$("input[name='login']").change(function(){
alert($("input[name='login']:checked").val());
});
Note that quote marks are also required.
See the API reference for the attribute equals selector.
Remove the @
. $("input[name=login]")
You probably also want to use this
in the callback:
$(document).ready(function() {
$("input[name=login]").change(function(){
alert($(this).val());
});
});
Just $("input[name=login]")
works for me. Never seen the @
used in that context before, is it supposed to be doing something?
Remove @
symbol from your selectors, since it doesn't exists on jQuery 1.5.2.
Here is your Fiddle updated.
You need quotes around the attribute value, 'login'. Also, I don't think you need the @ symbol:
$("input[name='login']").change(function(){
alert($("input[name='login']:checked").val());
});
Lose the @ symbol in the selector.