How can I get the text of a hidden element in Jquery?
I have the following css and html...
.hide
{
display:none;
}
<div>
<span class='kar开发者_StackOverflow社区dashian hide'>Kimmy</span>
</div>
with the following jquery.
$('div').live('click', function(){
alert($('kardashian', this).val());
});
If I remove the "hide" class I get "Kimmy" like I would expect but when it has the "hide" class I get nothing? How can I get the text of a hidden element in Jquery?
You just need a proper .class selector and .text() (.val() is for inputs), like this:
$('div').live('click', function(){
alert($('.kardashian', this).text());
});
The visibility of the element doesn't really affect anything, it'll work whether it's hidden or not.
Use .text() instead:
alert($('.kardashian', this).text());
The .val() method is used to get the value property of form inputs.
You forgot the class indicator. Use .kardashian
加载中,请稍侯......
精彩评论