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'>
开发者_JAVA百科
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
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')
$('input[type=hidden]').attr('value');
精彩评论