tags:

views:

115

answers:

2

How could I get the value of a element by name instead of by ID eg if I use by id it would be $('#id').val();

+10  A: 

Use the name attribute selector:

$("input[name=nameGoesHere]").val();
Nick Craver
Also note that having the type of the element isn't necessary.
thenduks
+1 for you Nick, because you were able to understand the question.
Balon
@thenduks: While this is true...name is usually found on inputs, and this does make the selector much faster.
Nick Craver
Fair enough, just pointing out that it works without it.
thenduks
+8  A: 
$('[name=whatever]').val()

The jQuery documentation is your friend.

thenduks
+1 for documentation is your friend
Natrium