Blogger Ever

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.
Blogger

2013-2016 Copyright Blogger E\ver . Coded, managed and founded by Mohammad Hamza (@hamzadhamiya) . Hosted on Blogger and fonts used are Raleway and Open Sans.