Hulk
Hulk

Reputation: 34170

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 this be prevented

 <a href='#' onclick='javascript:toggle(%s);'>Details</a>&nbsp;&nbsp;%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..

Upvotes: 2

Views: 149

Answers (2)

rahul
rahul

Reputation: 187060

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

Upvotes: 1

sberry
sberry

Reputation: 132018

Change you href to

href="javascript:void(0);"

Upvotes: 1

Related Questions