This is probably a silly question.
I have this class
<div class="about_us aperto">
how do I call it in a JS function? I'm trying:
$('.about_us aperto').click(function(){...
$('.about_us .aperto').click(function(){...
but they do not work.
This is probably a silly question.
I have this class
<div class="about_us aperto">
how do I call it in a JS function? I'm trying:
$('.about_us aperto').click(function(){...
$('.about_us .aperto').click(function(){...
but they do not work.
You have to connect them. The proper selector would be:
$('.about_us.aperto')
If you wants to select an element having multiple classes like <div class="classA classB ClassC"></div>
then just join them together in JavaScript i.e. $('.classA.classB.classC').click(function() {...});
$('.about_us.aperto').click(function() {
$(this).toggleClass('active');
});
.active {
background: #0f0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="about_us aperto">
<p>Lorem ipsum dolor sit amet</p>
</div>