is it possible with jquery to use DOM to find an a link inside a div, such as
<div id="something">
<a href="somewhere" title="something">
<img>
</a>
</div>
and append a datum to the link – in my case a google events tag:
onClick="_gaq.push(['_trackEvent', ' PDF Downloads', ‘Click', 'SEO For Beginners');"
dynamically to the a link so that the end result would be:
<div id="something">
<a href="somewhere" title="something" onClick="_gaq.push(['_trackEvent', ' PDF Downloads', ‘Click', 'SEO For Beginners');">
<img>
</a>
</div>
thank you for your time; any help would be greatly appreciated
2
Answers
It would be better if you just catch desired element with selector and bind a function to it, instead of binding a function directly in DOM.
you find the div you need by id, and by using function
find()
you serach youra
tag.After that you just refer to the DOM object of your tag by
tag[0]
and setonClick
whatever you like.