views:

152

answers:

2

I'm trying to select an select element by name I found this thread showing how to do it, and I followed it but I'm getting Syntax error. I'm 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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
    <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 any insight.

MS

A: 

You'll want to use $('select[name="country[0]"]') instead.

Using XPath in your selectors, which includes prefixing attribute names with @ has been removed from jQuery.

For more information, see the documentation of the attributeEquals selector.

Sebastian P.
+1  A: 

I ended up figuring this out by removing the @ symbol:

$('select[name="country[0]"]').val()

What does/did the @ symbol do?

Mark Steudel
the @ symbol is valid xpath for attributes. it's deprecated in 1.3+esque jquery.
meder