Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery click brings me to top of page. But I want to stay where I am

I have a simple click and show, click and hide button, but when I click it, the page anchors at the top of the page. Is there anyway to prevent this? So that when I click the button, I stay at the same place in the browser?

My code is..

$('#reportThis').hide();

$('#flagThis').click(function () {
    $('#reportThis').show("slow");
});
$('#submitFlag').click(function () {
    $('#reportThis').hide("slow");
});
like image 940
Trip Avatar asked Jun 10 '09 16:06

Trip


1 Answers

Try this:

$('#reportThis').hide();

$('#flagThis').click(function (evt) {
        $('#reportThis').show("slow");
        evt.preventDefault();
});
$('#submitFlag').click(function (evt) {
        $('#reportThis').hide("slow");
        evt.preventDefault();
});
like image 87
Darin Dimitrov Avatar answered Nov 16 '22 01:11

Darin Dimitrov