Here i am trying to get value of span that is 1 here .text()
is showing proper value but .val()
is not showing anyting
<span class="commentpageno" id="commentpageno_1111" style="visibility: hidden">1</span>
$('.commentpageno').click(function (e) {
alert($('.comment_page_no').text());
alert($('.comment_page_no').val());
});
val() is not used for span or div it is used for input control like text, checkbox etc
The .val() method is primarily used to get the values of form elements such as input, select and textarea. In the case of elements, the .val() method returns an array containing each selected option; if no option is selected, it returns null, jQuery docs
The .text() method cannot be used on form inputs or scripts. To set or get the text value of input or textarea elements, use the .val() method. To get the value of a script element, use the .html() method, jQuery docs
Your class name is commentpageno
and you are listening on comment_page_no
Do
alert($('.commentpageno').text());
as .val()
would not work for span.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With