jquery – Retrieve the href value of a link inside a div

Posted in programmer on Agosto 20th, 2009 by admin

There is a short way to set <a> href value as a click event for full container. It’s useful when we need to set whole area to be active.

atodiv

Set click event for container from a href inside.

JAVASCRIPT

$("div").click(function () {
window.location=($(this).find("a.go").attr("href"))
});

HTML

<div>
<p> ... any content ... </p>
<a class="go" href="http://www.metalmap.org">link</a>
</div>

Specific class needed if there is more than one <a> tag inside parent container.