If you do not have an identifier and there is no selector library, and you want it to work in older browsers, this requires a bit more work. If you can put an identifier in it, it's pretty simple. If not, more code is required:
var links = document.getElementsByClassName("MyClass"); links[0].onclick = function() {
Since getElementsByClassName not available in older browsers, you will need a pad to implement it if it is missing. Or you can get all the links in your document with:
var links = document.getElementsByTagName("a");
and then scroll through the list until you find the one you need (possibly checking the class name).
If you can put the id in the link:
<a href="http://braza.com/share" id="specialLink" class="MyClass" >Yummy</a>
Then it just accepts this code:
document.getElementById("specialLink").onclick = function() {
If you intend to do this regularly, adding an event listener is a bit more extensible than using the onclick property, but if you don't have a framework, you need a function to add an event listener that handles older versions of IE.
source share