html - How to put alert on my all anchor tag using javascript -
how put alert on anchor tag using javascript , alert box show link & text of anchor tag
you can document.getelementsbytagname, returns htmlcollection of elements given tag name.
eventtarget.addeventlistener method registers specified listener on eventtarget it's called on.
var anchors = document.getelementsbytagname("a"); (var = 0; < anchors.length ; i++) { anchors[i].addeventlistener("click", function (event) { event.preventdefault(); alert(this.href); alert(this.innerhtml); }, false); }
note: have use event.preventdefault(), cancel anchors default behaviour , addeventlistener
supported in ie9+
Comments
Post a Comment