I have a span tag like this <span id="myspan">1234 <a id="change"> </a> </span>
and now i want to get 1234 using jquery. Any sugeestion?? If my span has an id??
Use the textContent property to get the text of a span element, e.g. const text = span. textContent . The textContent property will return the text content of the span and its descendants. If the element is empty, an empty string is returned.
To get the value of div content in jQuery, use the text() method. The text( ) method gets the combined text contents of all matched elements. This method works for both on XML and XHTML documents.
Answers. var spanValue = $("#tetris-stats-lines"). html(); alert(spanValue);
jQuery: Set a value in a span Set a value in a span using jQuery. JavaScript Code: $(document). ready(function(){ $('#button1').
$('#change').parent('span').text()
or
$('span').text();
or
$('#myspan').text();
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