How can I change the text inside my <span> with jQuery?
I have a really simple question but开发者_如何转开发 it's something I have not done before. I have the following:
<td id="abc" style="width:15px;"><span></span></td>
I would like to put some text into the span.
How can I do this with jQuery. I know how to change things with the id of abc but not the code inside the span.
thanks,
$('#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
Syntax:
- return the element's text content:
$(selector).text()
- set the element's text content to
content
:$(selector).text(content)
- set the element's text content using a callback function:
$(selector).text(function(index, curContent))
JQuery - Change the text of a span element
$('#abc span').html("your new string");
精彩评论