In truth, this is a safer approach and probably what I should do for all examples, except I didn’t in the first place:
echo <<<SCRIPT
<script>
$("ul.menu a[href='" + window.location.pathname + "']")
.parentsUntil('.menu', 'li')
.addClass("current_page_item")
;
</script>
SCRIPT;
As you can see, this allows me to use both double-quotes and single-quotes with impunity.
I don’t know why this works, and I don’t know what to call it so that I can search for an explanation using terms. Ben can probably tell us more.