tags:

views:

54

answers:

2

Hi there,

is there a better way to write

$('#sender-name')[0].value;

instead of using the 0 element... Its an id so only 1 element should be present, is there some kind of FirstElement property or first child or something?

Basically i am returning it to a variable .. but of course jquery returns an array of items but it is an id so i not interested in the array just the first item..

Any ideas?

THanks

+11  A: 

Use the val function: returns the value of the first element for inputs.

var value = $('#sender-name').val();
tvanfosson
yep that was it !! thanks..
mark smith
+3  A: 

there's always $('#sender-name').get(0).value; but it's conceptually the same thing.

Do you mention value as simply an example of a DOM property, or is this specifically what you want? maybe $('#sender-name').val() would help if you don't absolutely need the DOM object.

Javier