Reputation: 717
I need to write jQuery code that when I click anywhere on the div I call it an event of jQuery, and when they click on a specific item, that within this div, do not call the click event. The class "testes" should not call the click.
However, the structure that I have to use is as below, because it is a specific jQuery.
Below is the code:
HTML:
<div class="tiles red">
<div class="live-tile" id="tile1" data-mode="flip">
<div>
<div class="testes"><a class="full" href="#"><p>* CNAE<br /></a></div>* CBO<br />* CID-10<br /></p>
<span class="tile-title"><p>Clique para voltar</p></span>
</div>
<div>
<p>Cadastros básicos</p>
<span class="tile-title">back title</span>
</div>
</div>
</div>
JQuery:
$(function () {
$(".live-tile").click(function () {
$(this).liveTile('play');
});
});
Thanks
Upvotes: 0
Views: 203
Reputation: 150
A few others answered your question while I threw together the code in JS fiddle. But, here is specifically how to do it for your code.
$(function () {
$(".live-tile").click(function () {
alert(".live-tile");
});
$(".testes").click(function(e) {
alert(".testes");
e.stopPropagation();
});
});
More info on event bubbling and stopping propogation.
Upvotes: 0
Reputation: 2166
You can .bind()
the event to your element and prevent bubbling:
$(".live-tile").bind("click", function(){
$(this).liveTile('play');
}, false)
This form of bind()
is a jQuery function of the form:
.bind( eventType [, eventData ], preventBubble )
Upvotes: 0
Reputation: 73906
Try this using event.stopPropagation():
$(function () {
$(".live-tile").click(function () {
$(this).liveTile('play');
});
$(".testes").click(function (e) {
e.stopPropagation();
});
});
Upvotes: 4