How to change Span content using jQuery?
<span class="stbuttontext" st_page="home">ShareThis</span> I want to change "Share this" to "Share",
please let me know the solution.
thanksl,
You can do the following:
$('.stbuttontext').text('Share'); for text content or
$('.stbuttontext').html('Share'); for html content.
In your case, however, the first statement must be accurate :)
This is my way of thinking about when to use .html () vs .. ().
Use .html () if you want to add style to the html tags to the text you are replacing, for example:
$('.stbuttontext').html('<strong>Share</strong>'); This is useful when you display an error message because you can add a class to change the color of the text.
$('#error').html('<span class="errortext red"><strong>Error:</strong> <em>Fix your email address</em></span>');` Use .text () when you just want to change the text .
So, if you did the above example with .text:
$('#error').text('<span class="errortext red"><strong>Error:</strong> <em>Fix your email address</em></span>');
The text that the user sees on the web page (without spaces in the tags, I could not figure out how to get him to work with this markup editor).
<span class = "errortext red"> <strong> Error: <em> Correct your email address </EM> </span>
and this text is not red or has bold or italic text.
$('.stbuttontext').html('Share'); $('.stbuttontext').html('Share');
Change the text of all spaces using the stbuttontext class.