I have an Anchor Tag like this
<a href="javascript:anchorScr()" id="anch1" class ="af-link"/>
It is taking me two clicks on the anchor tag to respond to the javascript function anchorScr();
function anchorScr() {
jQuery('a').click(function (event) {
var id = $(this).attr("id");
alert(id);
});
}
Am I doing something wrong? Why my anchorScr() is not called on the first click ?
This calls the
anchorScrfunction when the anchor is clicked:The function then attaches a
clickevent handler to allaelements.Remove the
hrefand just have this:The code will execute – attaching the
clickevent handler to allaelements. You should probably only run this onready()to ensure that the page has fully loaded into the DOM.