jquery hyperlink characteristics
In the following code why is that on click of details the page zoom shifts to top of the page and how can th开发者_StackOverflowis be prevented
<a href='#' onclick='javascript:toggle(%s);'>Details</a> %s %s <b>Total Sal: </b>%s<br><div id='%s' style='display:none;'>%s</div><br>"%(divname,first_name,lastname,usage,divname,html_table)
Note: the above code is generated on the server side..
Change you href to
href="javascript:void(0);"
You can put a return false
at the end of onclick event which will prevent the default action.
<a href='#' onclick='javascript:toggle(%s); return false;'>Details</a>
Since you are using jQuery this is not the way you call functions in jQuery. Use unobtrusive way of coding. Something like
$("#anch").click(function(){
// your code for click event
// $("#togg") will get the div element wrapped as a jQuery object
return false;
});
<a href='#' id="anch">Details</a>
<div id="togg"></div>
Note
You id seems to be invalid.
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
Read more
精彩评论