So, I'm working on a webpage that has a small "notepad" widget, and I've updated the interface to work as follows:
- The notepad is actually just a styled
<ul>
with each line on the notepad page as its own<li>
. - The user can simply click and type to add a new
<li>
because it iscontenteditable: true
. - Each newly added line is placed in a
<p>
element, and styled with jQuery.
Now here's my jQuery issue... The code below successfully adds the "strikethrough" class to the <p>
element when double-clicked, and then removes it when double-clicked again. HOWEVER, if I click the "notepad" to add a new <p>
element, the jQuery script below doesn't work. It only applies to <p>
elements that were already on the page when the document loaded the first time.
// NOTEPAD INTERFACE
$(".paper p").dblclick( function() {
$(this).toggleClass("strikethrough");
});
Does anybody know how to make the same jQuery apply to every <p>
element equally, regardless of when it was added to the DOM?