anchor inside a clickable div
Asked Answered
A

1

6

I have this problem with a click script I have connected to a div. The thing I'm trying to accomplish is that when you click on an URL inside the clickable div, the click event wont be called, and you will be directed to whatever the anchor is calling.

This is the JS

<script type="text/javascript">
$(document).ready(function()
{
    $(".comment_button").click(function(){

    var element = $(this);
    var I = element.attr("id");

    $("#slidepanel"+I).slideToggle(300);
    $(this).toggleClass("active");

    return false;
    });
});
</script>

And this is the html

<div class="comment_button" id="<?=$klotter_info['id']?>" style="cursor:pointer;">
<?=sanitize($klotter_info['message'])?> // Kommer i vissa fall ha länkar i sig
</div>

Any help is greatly appreciated! Thanks in advance.

Ascham answered 2/5, 2011 at 16:51 Comment(0)
E
16

make click handler for your anchor and call stopPropagation:

$('a').click(function(event){
   event.stopPropagation();
});

This will disable event bubbling. and div click won't be triggered.

Excurrent answered 2/5, 2011 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.