(Im using the before()
function from jquery to append a new <p>
element to a div layer.
$('#AddParagraphButton').click(function() {
$('#TheLayer').before('<p contentEditable='true'>Some text...</p>');
});
here I have set keypress
function to insert <br>
tag.
$('p').keypress(function(e){
if(e.which == 13){
e.preventDefault();
document.execCommand('insertHTML', false, '<br/>');
}
});
开发者_如何学编程
this works fine(br tag inserts) until the append function is called and a new <p>
is added. How do I get livequery to unbind the keypress event and bind again?
EDIT: the <p>
tags have the contentEditable property. Im doing this because the <br>
tags are wrapped in divs and I only want <br>
tagsHave you considered using the built in live()
functionality?..
Description: Attach a handler to the event for all elements which match the current selector, now and in the future.
$('p').live("keypress", function(e){
e.preventDefault();
if(e.which == 13){
document.execCommand('insertHTML', false, '<br/>');
}
});
精彩评论