The following is my code snippet:
$(document).ready(function()
{
$('table#example td a.delete').click(function()
{
if (confirm("Are you sure you want to delete this row?"))
{
alert("You Press OK");
}
});
});
My grid-view is on the bottom of the page. Either I press Ok or Cancel Button, page moves to TOP.
I want to remain the same position. How to control this.
It actually doesn’t have anything to do with the
confirm; it’s the fact you’re clicking a link (I’m guessing the link has eitherhref=""orhref="#"in it). The browser is following the link, which is the default action for theclickevent of links.You need to prevent the default action, which you can do by returning
falsefrom your function, or by accepting theeventargument to yourclickfunction and callingevent.preventDefault().Returning
false(which both prevents the default action and stops the click bubbling to ancestor elements):Using
preventDefault(which only prevents the default, and doesn’t stop bubbling; ancestor elements will also see the click):