$(".continue--btn").hide();
$('.generator--templates').click(function() {
// reset the sibling elements
$(this).siblings('.generator--templates').each(function(i, el) {
$(el).find('.continue--btn').hide();
$(el).css('background', 'rgba(0, 0, 0, 0.2)');
$(el).find('.generator--templates__description, .generator--templates__purpose').css("color", "transparent");
});
// apply changes to clicked item
$(this).find('.continue--btn').show();
$(this).css("background", "#03A9F3");
$(this).find('.generator--templates__description, .generator--templates__purpose').css("color", "#fff");
});
$('.body').click(function(e) { // change '.body' to 'body' for your code
var $target = jQuery(e.target);
if ($target.hasClass('generator--templates') ||
$target.closest('.generator--templates').length > 0) {
// Clicked on a box
} else { // Clicked elsewhere
$('.generator--templates').each(function(i, el) {
$(el).find('.continue--btn').hide();
$(el).css('background', 'rgba(0, 0, 0, 0.2)');
$(el).find('.generator--templates__description, .generator--templates__purpose').css("color", "transparent");
});
}
});
.body {
/* added just for display */
background: rgba(0, 0, 0, 0.1);
width: 100%;
height: 500px
}
.generator--templates {
background-color: rgba(0, 0, 0, 0.2);
width: 150px;
height: 150px;
float: left;
margin-right: 10px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1) inset
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="body">
<div class="container-element">
<div class="generator--templates one">
<button class="continue--btn">Continue</button>
</div>
<div class="generator--templates two">
<button class="continue--btn">Continue</button>
</div>
<div class="generator--templates three">
<button class="continue--btn">Continue</button>
</div>
</div>
</div>
請你的問題明確,直奔要點,我不明白你想要什麼,我也幫不了你。據我所知,你可以試試''(document).click(function(){$('#divid')。addClass(「redColor」)});' – vietnguyen09
你試過用'body'標籤嗎? –
也許這會幫助你[codepen](https://codepen.io/bassta/pen/ndfDq) – JustARandomProgrammer