Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the text inside my <span> with jQuery?

Tags:

jquery

People also ask

How do I change text in 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.

Can we add style in span?

The span tag is just like a div, which is used to group similar content so it can all be styled together.


$('#abc span').text('baa baa black sheep');
$('#abc span').html('baa baa <strong>black sheep</strong>');

text() if just text content. html() if it contains, well, html content.


This will be used to change the Html content inside the span

 $('#abc span').html('goes inside the span');

if you want to change the text inside the span, you can use:

 $('#abc span').text('goes inside the span');

$('#abc span').html('A new text for the span.');

Try this

$("#abc").html('<span class = "xyz"> SAMPLE TEXT</span>');

Handle all the css relevant to that span within xyz