I'm trying to use jquery and click() to grab the url of an image link once its clicked. The html looks like this.
<div class="lp-element lp-pom-image" id="lp-pom-image-167" >
<a href="http://url.com/page" target=""><img src="/image.jpg" alt=""></a>
</div>
The javascript I'm using so far looks like this but it isn't grabbing the url of the clicked image link. The url needs to be passed to where the variable this is.
jQuery(function() {
jQuery("#lp-pom-image-167").click(function() {
trackOutboundLink(this, 'AddToCart', 'Bottom CTA');
return false;
});
});
How do I pull the href url with the appropriate base URI? ie. "http://url.com/page"?
EDIT:clarified what i am trying to pull out.
$(this).children("a img").attr('src')should do the trick.<worried>Hope you don't intend to copy paste this(any) JS code like this one 200 times for all your#lp-pom-image-NNNelements....</worried>.propshould be used instead of.attr.