开发者

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'>
开发者_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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜