Dave's Brain

Browse - programming tips - jquery select by name

Date: 2011feb3
Language: javaScript

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.
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: