Dave's Brain

Browse - Programming Tips - With jQuery, how do you select an element by name (not id) ?

Date: 2011feb3
Language: javaScript
Library: jQuery

Q.  With jQuery, how do you select an element by name (not id) ?

A.  If you have 

<input name=myfield>
You select it with [name=myfield] like this:
<script> value = $('[name=myfield]').val(); // or $('[name=myfield]').change(function{} { alert('it changed'); }); </script>
My feeling is that if you already have a name for a field why add an id just to select it.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.