开发者

Obtain a HTML elements hidden value

I have a H开发者_如何学运维TML element like so:

<select>
   <option id="a" hidden"1">Abcdefgh</option
</select>

And, using javascript, I want to retreive the hidden value from the option element.

How do I do this?

var hiddenVal = document.getElementById( "a" ).hidden; // this doesnt work


Not all attributes map directly to properties. You should be able to use the native .getAttribute() to get the value of custom attributes.

var hiddenVal = document.getElementById( "a" ).getAttribute('hidden');
<select>
   <option id="a" hidden="1">Abcdefgh</option>
</select>


Well first off your mark up on your HTMl is all off. You are missing an end tag on the element and you would need to put hidden="1" with the equals and quotes. But is hidden even a valid attribute for an option element?? I dont think it is.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜