开发者

Prepend and Append at the same time

开发者 https://www.devze.com 2023-01-01 13:51 出处:网络
$(\'.testimonials blockquote p\') .prepend(\'<span class=\"quo ldquo\">&ldquo;</span>\')
$('.testimonials blockquote p')
.prepend('<span class="quo ldquo">&ldquo;</span>')
.append('<span class="quo rdquo">&rdquo;</span>'开发者_如何转开发);

...prepends and appends TWICE. How do I prepend ldquo + whatever content inside the p + rdquo?

Thanks!


Your code doesn't prepend/append twice at this end. When I run it against this test HTML

<div class='testimonials'>
<blockquote><p>Testing</p></blockquote>
<blockquote><p>One</p></blockquote>
<blockquote><p>Two</p></blockquote>
<blockquote><p>Three</p></blockquote>
</div>

...I end up with each paragraph in quotes (just one pair, not two).

Perhaps your CSS is applying the quotes (look at the quo and ldquo/rdquot CSS classes), and then of course you're also including them in your markup, and so ending up with two of each.


Maybe your selector matches 2 elements, or you have incorrectly nested p elements.

You could add a :first, or try this to see how many it is matching

alert($('.testimonials blockquote p').length);

or see what they are matching like this

$('.testimonials blockquote p').css({ border: '1px solid red' });
0

精彩评论

暂无评论...
验证码 换一张
取 消