What I want to do is prevent the click on the div if a users clicks a link inside that div. but without using the .click(function() {}); on the link.
Here's the code:
$('div.feature').click(function() { window.location = $(this).attr('rel');});
here's an example content of the div:
<div id="feature" rel="urlnumberone">
some text
<a href="javascript:topicchange(this);" class="insideLink">Link</a>
</div>
And for some specific reason I can't use something like this
$('.insideLink').click(function(event){
event.stopImmediatePropagation();
});
I have to use this "topicchange()" function, is there any way to prevent the event propagation?
Thanks!
Is this allowed? The topic change function is called directly from the href, but the click event is prevented from propagating. Or but everything take place in topicchange?
The example that you've provided should work, except that your div has an id of 'feature', but in the js you're targeting a class. jsfiddle.net/SNP3K.
.
Easy as that!
According to http://api.jquery.com/bind/, event.stopPropagation should allow other event handlers on the target to be executed. You can still execute from the Href but you can also handle the default click bubbling to the div by ignoring it.
Full demo at: http://jsfiddle.net/leomwa/qrFQM/
Snippet:
Very similar to @shanethehat.
Kudos to @shanethehat for asking for a clarification.