Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the text inside a span using jquery

Tags:

html

jquery

text

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??

like image 705
ACP Avatar asked Aug 01 '13 12:08

ACP


People also ask

How do I get text inside a span?

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.

How do I get text inside a div using jQuery?

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.

How can get span value using ID in jQuery?

Answers. var spanValue = $("#tetris-stats-lines"). html(); alert(spanValue);

How do you value a span?

jQuery: Set a value in a span Set a value in a span using jQuery. JavaScript Code: $(document). ready(function(){ $('#button1').


1 Answers

$('#change').parent('span').text()

or

$('span').text();

or

 $('#myspan').text();
like image 93
Anton Avatar answered Nov 14 '22 23:11

Anton