Return False :-
Basically returning false is a way to tell your action (like button click event, submit and load etc. ) is not firing. Return false do the three basic things
- event.preventDefault();
- event.stopPropagation();
- Stops the callback execution and returns immediately when called.
Example:-
$(document).ready(function(){
$("#buttonSubmit").click(function(event){
$("body").append($(this).attr("href"));
return false; // "cancel" the default behaviour
})
});
Prevent Default :- The prevent Default prevents the default action the browser makes on that event.
If this method is called, the default action of the event will not be triggered.
For example, clicked anchor will not take the browser to a new URL.
If any method or function has been called by any event handler and we want to triggered the event then we can use event.isDefaultPrevented().
$("a").click(function(event) {
event.preventDefault();
$('#div1').append('default ' + event.type + ' prevented').appendTo('#InfoMessage');
});
Stop Propagation :- This will stops the event from bubbling up the event chain.
Example:-
$("p").click(function(event){
event.stopPropagation();
alert("The paragraph element was clicked.");
});
0 Comment(s)