I have the following css and html…
.hide
{
display:none;
}
<div>
<span class='kardashian 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
.classselector and.text()(.val()is for inputs), like this:The visibility of the element doesn’t really affect anything, it’ll work whether it’s hidden or not.