JQuery, fetching form elements by name, getting: Error: uncaught exception: syntax error, unrecognized expression: [@ name = "reset"]
I am trying to select a select element by name, I found this thread showing how to do this and I followed it but I am getting a syntax error. I am using jquery 1.4.1, here's my code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>TODO supply a title</title>
<script type="text/javascript" src="/js/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
alert( $('select[@name="country[0]"]').val() );
})
</script>
</head>
<body>
<form>
<select name="country[0]">
<option value="23">test</option>
</select>
</form>
</body>
</html>
Thanks in advance for your understanding.
MC
+2
a source to share
2 answers
You want to use instead $('select[name="country[0]"]')
.
The use of XPath in your selectors, which includes the c attribute prefix names @
, has been removed from jQuery.
For more information, see the documentation for the attributeEquals selector .
+2
a source to share