Main Problem : Get rid of # when user clicks on anchor tag. I found a solution for this, which is adding return false; in onClick handler
Secondary Problem : My current code looks like this
<a href="#" onclick="javaScript:toggleDisplay();" title="Some Title">
@ViewBag.TotalRecords
</a>
And according to solution I got, I want it like this
<a href="#" onclick="javaScript:toggleDisplay();return false;" title="Some Title">
@ViewBag.TotalRecords
</a>
- How can I append
return false;to my javaScript function call? I can do it manually, but is there any easy way to do this. I am using jQuery? - Is there any other way to get rid of
#, without modifying the current markup?
EDIT
@ViewBag.TotalRecords: This is a MVC3 ASP.Net thing, but it is not related to the question, hence I didn’t put it in the tags.
Thanks
Thanks Phil, as I said got something out of it. Got not one but two solutions.
If I add following code to js File, all
clickhandlers are handled (will make it specific foranchorlater on)Using plain JavaScript (Unobtrusive JavaScript)
Using jQuery
The jQuery Solution is little different than the one suggested by elclanrs, in the sense, if I do
$('a').click(function(e){ e.preventDefault(); });, it works foranchor, but I modify my DOM and add newanchorto it, click on this anchor causes#in query string.EDIT
The above solution causes all the clicks to go through the handler, even which I don’t want. Because of this normal
anchorwithhrefas url were not working, so this is the working solutionHope this helps some one else.