1
How can I use the function click in jquery with classes of the same name? Type click and appear the element only in the clicked div and not in the others. I’ve tried to use $(this).next('bla').addClass('blablabla')
and did not succeed.
1
How can I use the function click in jquery with classes of the same name? Type click and appear the element only in the clicked div and not in the others. I’ve tried to use $(this).next('bla').addClass('blablabla')
and did not succeed.
2
Simple use the method find
:
$(document).ready(function() {
$('.lista').click(function() {
$(this).find(".item").toggleClass('green');
});
});
.lista {
border-bottom: 1px solid #ccc;
cursor: pointer;
margin-bottom: 14px;
padding-bottom: 14px;
}
.item {
}
.green { color: green; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="lista">Clique para mudar a cor do item:<div class="item">pt.stackoverflow.com</div>
</div>
<div class="lista">Clique para mudar a cor do item:<div class="item">pt.stackoverflow.com</div>
</div>
Browser other questions tagged javascript html jquery css
You are not signed in. Login or sign up in order to post.
I did not understand your question very well, you want that even if you have equal classes, it is inserted only in the one that was clicked?
– Woton Sampaio
Put the code in the question. This way is not clear.
– Sam
I want to click on a class that has the same name as the others, only to add a class just clicked on.
– darknone
@darknone already tried to use an id?
– Woton Sampaio
It hasn’t worked either
– darknone
I’ve solved it, I just used siblings :)
– darknone
I could post your code to see how it turned out!
– Márcio Ricardo