You can add the handler like so:
function anchorClicked(){
console.log("clicked");
}
window.onload = function(){
var anchors = document.getElementsByClassName('bganch');
for(var i=0; i<anchors.length; i++){
anchors[i].onclick = anchorClicked;
}
};
The above adds the click event to elements with the bganch
class.
Other options:
- Give the anchor an ID and use
document.getElementById('someid')
- Get all anchors by the tag name using
document.getElementsByTagName('a')