First of all, there are some small errors in your code:
The source tag <img>
is passed by the parameter src
, even because it doesn’t "close" this tag, look how it should look:
<img class='Camiseta' src="camiseta.jpg" />
Another thing, avoid using graphic accents in parameters, such as the id and the class. So from "Description" I went to "Description".
Done this, you can just do so:
$('.CamisetaTudo .Descricao').hide(); //Esconde todas as descrições
$('.CamisetaTudo .Clique').click(function(){
$(this).closest('.CamisetaTudo').children('.Descricao').toggle();
});
I used the method .closest()
capturing the predecessor element, and the method .children()
captures the children of some elements from a parameter.
I also used the .toggle()
that gives a hide/show
.
There are several other ways, this at least will ensure that the elements with the class the description in question are within the div.CamisetaTudo
.
Example:
$('.CamisetaTudo .Descricao').hide(); //Esconde todas as descrições
$('.CamisetaTudo .Clique').click(function(){
$(this).closest('.CamisetaTudo').children('.Descricao').toggle();
});
img{
width: 100px;
}
.CamisetaTudo .Clique{
font-weight: bold;
color: darkBlue;
font-family: sans-serif;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='CamisetaTudo'>
<img class='Camiseta' src="http://defesa.org/ocart/image/data/Camiseta%20Medidas.png" />
<p class='Clique'>Clique aqui</p>
<p class='Descricao'>Descrição aqui</p>
</div>
<div class='CamisetaTudo'>
<img class='Camiseta' src="http://defesa.org/ocart/image/data/Camiseta%20Medidas.png" />
<p class='Clique'>Clique aqui</p>
<p class='Descricao'>Descrição aqui</p>
</div>
You can use more "beautiful" effects like the .toggleSlide()
, I made this example as I said, clicking on the T-shirts, so I removed the "click here":
$('.CamisetaTudo .Descricao').hide();
$('.CamisetaTudo .Camiseta').click(function(){
$(this).closest('.CamisetaTudo').children('.Descricao').slideToggle('fast');
});
img{
width: 100px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='CamisetaTudo'>
<img class='Camiseta' src="http://defesa.org/ocart/image/data/Camiseta%20Medidas.png" />
<p class='Descricao'>Descrição aqui</p>
</div>
<div class='CamisetaTudo'>
<img class='Camiseta' src="http://defesa.org/ocart/image/data/Camiseta%20Medidas.png" />
<p class='Descricao'>Descrição aqui</p>
</div>
Post your code Ney, help us help you :)
– Samir Braga
yes yes I realize that and I’m learning :)
– Ney
Very good.. that’s right ;) For your question, just post your html, t-shirts and javascript you’ve used...
– Samir Braga
Ney, look what you wanted..
– Samir Braga