[jQuery] Odd behaviour with the "one()" event handler
I'm not sure if I'm misinterpreting how to use the "one()" event handler
properly, but when I tried to use it in the bit of code below, I was unable
to prevent the button from submitting the form (which it was now inserted
into). I tried "return false" as well as an "event.preventDefault()", but
clicking on the button still seemed to submit the form.
The only way I could get it to prevent submitting the form was to use the
.mouseup() event handler rather than .one().
Why didn't "return false" or "event.preventDefault();" stop the form from
being submitted?
The piece of code:
$('#modewc').parent().append('<br /><br /><button style="font-size:10px;"
id="remHwb">Remove Word Breaks</button>');
if(!$("a[@name='preview']")[0]){
$('#remHwb').attr('disabled','disabled');
}
else{
$('#remHwb').one("mouseup", function(e){
e.preventDefault();
var sdf = $.trim($('.bodytext:last>p').html()).split("\xAD\x20")
$('#body').val('');
for(var p=0;p<sdf.length;p++){
if( (p == sdf.length-1) && ((sdf[p].length<34) || (sdf[p].indexOf(' ')>
0)) ){
$('#body').val($('#body').val()+sdf[p].replace(RegExp("
", "gim"),
"\n"));
break;
}
else{
sdf[p] = sdf[p].slice(0,-2)+'[**]'+sdf[p].slice(-1);
}
sdf[p] = sdf[p].replace(RegExp("
", "gim"), "\n");
$('#body').val($('#body').val()+sdf[p]);
}
$(this).attr('disabled','disabled');
return false;
});
}
--
View this message in context: http://www.nabble.com/Odd-behaviour-with-the-%22one%28%29%22-event-handler-tp16790652s27240p16790652.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.