jQuery DIV click, with anchors

Posted by ANaimi on Stack Overflow See other posts from Stack Overflow or by ANaimi
Published on 2008-10-07T20:19:40Z Indexed on 2010/04/16 15:03 UTC
Read the original article Hit count: 181

To make click-able divs, I do:

<div class="clickable" url="http://google.com">
    blah blah
</div>

and then

$("div.clickable").click(
function()
{
    window.location = $(this).attr("url");
});

I don't know if this is the best way, but it works perfectly with me, except for one issue: If the div contains a click-able element, such as <a href="...">, and the user clicks on the hyperlink, both the hyperlink and div's-clickable are called

This is especially a problem when the anchor tag is referring to a javascript AJAX function, which executes the AJAX function AND follows the link in the 'url' attribute of the div.

Anyway around this?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about web-development