d.mc2
d.mc2

Reputation: 1129

Selecting same id but different type

I have 2 inputs with the same id but different types:

<input id='aid' type='text' value='text value'>
<input id='aid' type='hidden' value='hidden value'>

I am trying to use

alert($(**INSERT SELECTOR HERE**).attr('value'));

to select and show the value "hidden value"

What selector can I use? '#aid:hidden' doesnt seem to work.

I attached a jsfiddle. http://jsfiddle.net/L8TtT/1/

Thanks

Upvotes: 0

Views: 164

Answers (2)

SLaks
SLaks

Reputation: 887275

You cannot have multiple elements with the same ID.

Use a class name instead:

<input class='aid' type='text' value='text value'>
<input class='aid' type='hidden' value='hidden value'>

You can then write $('.aid:hidden')

Upvotes: 5

kinakuta
kinakuta

Reputation: 9037

$('input[type=hidden]').attr('value');

Upvotes: 2

Related Questions