如何通过jquery在运行时更改原始的html代码?

时间:2010-01-11 17:40:34

标签: jquery

<blockquote><p>We prefer questions that can be answered, not just discussed. Provide details. Write clearly and simply.If your question is about this website, ask it on meta instead.</p></blockquote>

我想将上面的代码改为此。

    <blockquote>
    <div class="quote_start"><div></div></div><div class="quote_end"><div></div></div>
    <p>We prefer questions that can be answered, not just discussed.
Provide details. Write clearly and simply.If your question is about this website, ask it on meta instead.</p>
    </blockquote>

2 个答案:

答案 0 :(得分:3)

使用前置方法

$('blockquote').prepend('<div class="quote_start"><div></div></div><div class="quote_end"><div></div></div>');

这将把文本作为所选对象的第一个子元素

答案 1 :(得分:1)

这是唯一的blockquote吗?如果是这样,你可以使用prepend /

$("blockquote").prepend("<div class='quote_start'><div></div></div><div class='quote_end'><div></div></div>");

否则,在进行前置之前,您需要找到一些方法来识别有问题的块引用。