eozzy
eozzy

Reputation: 68680

Prepend and Append at the same time

$('.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!

Upvotes: 0

Views: 1185

Answers (2)

T.J. Crowder
T.J. Crowder

Reputation: 1074248

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.

Upvotes: 2

alex
alex

Reputation: 490213

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' });

Upvotes: 2

Related Questions