ShareThis I want to change "Share this" to "Share", ...">

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,

+51
jquery html css
Apr 12 2018-10-12T00:
source share
4 answers

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 :)

+88
Apr 12 '10 at 13:16
source share

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.

+21
Apr 12 2018-10-12T00:
source share
 $('.stbuttontext').html('Share'); 
+6
Apr 12 2018-10-12T00:
source share

$('.stbuttontext').html('Share');

Change the text of all spaces using the stbuttontext class.

+2
Apr 12
source share



All Articles