insert text .before() INSIDE the tag with jquery
here's a basic example of what I'm trying to do:
<div class="container">
<h2>Greetings&开发者_开发百科lt;/h2>
<p>All this content, including the HTML comes from a CMS</p>
</div>
I want to insert some more content from the CMS like so
<div class="container">
<h2>Greetings</h2>
<p>NEW YORK - December 29, 2010 - All this content, including the HTML comes from a CMS</p>
</div>
This tag won't work, as it'll put it before the
tag...
$('.container p').before('NEW YORK - December 29, 2010');
so how can i insert it into the tag? I can't tag that p with a class or put a marker inside the
tag since it is being spit out of a CMS.
I found the prepend(), which seems to do what I want. That is another solution as well. Thanks!! http://api.jquery.com/prepend/
Use text().
var oldText = $('.container p').text();
$('.container p').text("NEW YORK - December 29: " + oldtext);
$('.container p').text(function(i,v) {
return "NEW YORK - December 29: " + v;
});
精彩评论