.gif)
Prevent default refers to a function get its original values when the page is refreshed.If you have multi tabs on a page and you select the second tab,after refreshing the page the first tab will be open automatically.Hence, to prevent the function to come to its original appearance,a simple Javascript function we use.
Lets suppose I have a Jquery code that is
$(document).ready(function(){According to the script if someone clicks on the div then it will be slide up.But,if the page is refreshed then the div will come back in its original shape,however sometimes we want the function to come back.But,if we do not want this function to come back then,we will use .preventDefault() function of Jquery.Check the script below.
$(div).click(function(){
$(this).slideUp
}):
});
$(document).ready(function(){The above is the sample of how to use this functions.
$(div).click(function(event){
event.preventDefault();
$(this).slideUp
}):
});
Further More
This function can be use in many ways such as in navigation menu.If a user clicks on any button then by using Javascript or Jquery you can add a class in it that will change the appearance of it,it will remain the button highlighted on refreshing page.Any other uses are Accordion menu and Multiple tabs.
Post A Comment:
0 comments: