Fix Quotes

Seems like it shouldn't be this hard...

by Sidney Collins

HTML

<div id="Z">
    <article id="131789309379" class="X">
        <div class="quote">
            <h3>
                &ldquo;
                <p>That was her.</p>
                <p>PURE, LUCID, EVIL.</p>
                <p>I’d sleep all right with that on top of me.</p>
                &rdquo;
            </h3>
            <div class="source">— Bertolt Brecht, from <a href="http://www.amazon.com/Bertolt-Brecht-Poems-1913-1956/dp/0878300724"><i>Poems 1913 - 1956</i></a>&nbsp; (via <a href="http://ancient-serpent.tumblr.com/" class="tumblr_blog">ancient-serpent</a>)</div>
        </div>
    </article>
    <article id="131752099889" class="X">
        <div class="quote">
            <h3>&ldquo;It simply isn’t an adventure worth telling if there aren’t any dragons.&rdquo;</h3>
            <div class="source">— <a href="http://wordsnquotes.com/tagged/j.r.r.-tolkien">J.R.R. Tolkien</a>&nbsp; (via <a href="http://wordsnquotes.com/" class="tumblr_blog">wordsnquotes</a>)</div>
        </div>
    </article>
</div>

CSS

.quote .left-quote:before {
    content: '“';
}
.quote .right-quote:after {
    content: '”';
}

JavaScript

var $K = $('#Z');
var fixQuotes = function() {
    var stripLeft = function() {
        var lq = this.previousSibling;
        if(lq != null) lq.parentNode.removeChild(lq);
    };
    var stripRight = function() {
        var rq = this.nextSibling;
        if(rq != null) rq.parentNode.removeChild(rq);
    };
    $K.find('.quote h3 p:first-of-type').addClass('left-quote').each(stripLeft);
    $K.find('.quote h3 p:last-of-type').addClass('right-quote').each(stripRight);
};
fixQuotes();