JavaScript:
<div onclick="alert('You clicked me !')">Click Me</div>
JQuery
$('#div_id').click(function(){
alert('Clicked !!');
});
<div class="myBox">
blah blah blah.
<a href="http://google.com">link</a>
</div>
JQuery
$(".myBox").click(function(){
window.location=$(this).find("a").attr("href");
return false;
});
The above code cancels the default link action (link to link) with return falseand binds the event clickwith the div to the class myBox, then it finds the link attribute srcinside the div and is window.locationused to redirect the page to the srclink attribute present inside the div. Thus, this basically makes the div interactive.
source
share