First of all, there are a few minor bugs in your code:
The source tag of the <img>
tag is passed by the parameter src
, even if you do not "close" this tag, look how it should look:
<img class='Camiseta' src="camiseta.jpg" />
Otherwise, avoid using graphical accents in parameters such as id and class . Then from "Description" I went to "Description".
Once you've done this, you can simply do this:
$('.CamisetaTudo .Descricao').hide(); //Esconde todas as descrições
$('.CamisetaTudo .Clique').click(function(){
$(this).closest('.CamisetaTudo').children('.Descricao').toggle();
});
I used the method .closest()
that captures the predecessor element, and the .children()
captures the children of some elements from a parameter.
I also used .toggle()
which gives hide/show
.
There are several other ways, this will at least ensure that the elements with the class description in question are within 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><divclass='CamisetaTudo'><imgclass='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"/><pclass='Clique'>Cliqueaqui</p><pclass='Descricao'>Descriçãoaqui</p></div>
Youcanusemorebeautifuleffectslike.toggleSlide()
,ImadethisexampleasIsaid,clickingontheT-shirts,soIremovedthe"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><divclass='CamisetaTudo'><imgclass='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>