Reputation:
Sorry for my bad english... I have a problem in jquery when i cklick a buttom is refresch a navigation... Somebody help me please :)
demo:
Upvotes: 1
Views: 8377
Reputation: 10646
This is happens often when you a form and you click on the submit button, to prevent the browser from refreshing the page just do this in the HTML :
<form onsubmit="return false;">
...
</form>
If you have a link of a button that refreshes the page, do this :
$('.myLinkOrButton').click(function(e) {
e.preventDefault();
...
});
Upvotes: 0
Reputation: 14312
Its hard to know without knowing exactly where the issue is, but you could need e.preventDefault() or e.stopPropagation() e.g.
$('.button').on('click',function(e) {
//do something
e.preventDefault(); // stops default button action, e.g. submitting a form
e.stopPropagation(); // stops event bubbling back to parent element
}
return false; /// stops default link action
});
where .button is the class of the element thats triggering the event. Note these are examples of issues you may be having, but without knowing the problem you are experiencing I can't say which - if any - will work.
Upvotes: 2
Reputation: 8266
You can do this by adding return false;
to the click function in jQuery.
Upvotes: 1
Reputation: 8640
If you are using a click event on an anchor tag, you need to use preventDefault
. For example:
$('.3').click(function(e){
e.preventDefault();
$('body').animate({
scrollTop: $(".middle").offset().top
}, 2000);
});
More info on how preventDefault
works: jQuery - event.preventDefault()
Upvotes: 4