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='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, as I expected, but when it has a hide class, do I get nothing? How can I get the text of a hidden element in jQuery?

+3
source share
3 answers

You just need the correct .classselector and .text()( .val()for input), for example:

$('div').live('click', function(){
   alert($('.kardashian', this).text());
});

The visibility of an element does not really affect anything; it will work regardless of whether it is hidden or not.

+4
source

Use instead.text() :

alert($('.kardashian', this).text());

.val() .

+1

. .kardashian

0

Source: https://habr.com/ru/post/1775718/


All Articles