I have an anchor element which does not have any class
or id
. I want to add a click handler to that anchor element. I tried in following way but no luck:
'<'a href="dosmthng" > do something</a>
var dosm = $('a[href^="dosmthng"]') //this works perfect it select anchor element
$(dosm).click(function() {
alert(" click() called.");
});
The click function throws an error:
VM556763:211 Uncaught DOMException: Failed to execute 'querySelector' on 'Document'.
Is there any better approach two achieve this?
P.S I can not change the HTML code in the file.