问题描述:

here's a basic example of what I'm trying to do:

<div class="container">

<h2>Greetings</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;
});
相关阅读:
Top