About

Labels

slider

Navigation

How to prevent the function to get default when page is refresh using Jquery?

How to prevent the function to get default when page is refresh using Jquery?

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(){
$(div).click(function(){
$(this).slideUp
}):
});
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.
$(document).ready(function(){
$(div).click(function(event){
event.preventDefault();
$(this).slideUp
}):
});
The above is the sample of how to use this functions.

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.
Share
Banner

Muhammad Hamza

Themelet provides the best in market today. We work hard to make the clean, modern and SEO friendly blogger templates.

Post A Comment:

0 comments: