To make divs clickable I use this:
$(".clickable").click(function (event) {
window.location = $(this).find('a').attr('href');
event.preventDefault();
});
I’m using an <asp:Repeater> in asp.NET to create several such <div>s.
The problem is that all clicks in the div are picked up by this jQuery – I also have an <asp:Button> inside the div, for this I want to catch the click as normal and process it in the repeater_ItemCommand event – But this doesn’t fire – the page just redirects to the href found in the hyperlink in the div.
Anyway I can stop this and make the button pick up as normal?
You need to check whether
event.targetis aninputelement (use thenodeNameproperty, or call$(event.target).is(...)).If it is, don’t do anything in your handler.