Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the content of the Span using jQuery?

Tags:

html

jquery

css

<span class="stbuttontext" st_page="home">ShareThis</span> 

I want to change "Share This" to "Share",

please let me know the solution.

thanksl,

like image 912
Swati Sharma Avatar asked Apr 12 '10 13:04

Swati Sharma


People also ask

How do I change the value of a span?

Use the textContent property to change the text of a span element, e.g. span. textContent = 'Replacement text' . The textContent property will set the text of the span to the provided string, replacing any of the existing content. Here is the HTML for the examples in this article.

How can create span tag dynamically in jQuery?

var span = $('<span />'). attr({'className':'folder_name' , 'text':'favre' }); var insert= $('<div/>', { className: "folder", html: span }); which yielded this result.

Can I add CSS to span?

The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute. The <span> tag is much like the <div> element, but <div> is a block-level element and <span> is an inline element.


1 Answers

You can do with either:

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

for textual content or

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

for html contents.

In your case however, the first statement should be fine :)

like image 144
Sarfraz Avatar answered Oct 09 '22 10:10

Sarfraz