html:
<div class="a">
<div class="g"></div>
<a class="e">Link</a>
<div class="g"></div>
<a class="e">Link</a>
</div>
I want to hide the div with class “g” whenever I click on the link.Only that particular link.Suppose if i clicked on the first link then the first div with class “g” should hide only.Now wat i’ve done is here.
Jquery:
$('.e').click(function(){
c();
});
function c(){
$(.g).hide();
}
but this is hiding all the elements of class “g”.
Both the div with class “g” and link are generated by the users dynamically and i dont know how many the users can generate.
Currenctly you are calling
$('.g').hide()which is selecting all the element with g as the class and hiding them all.Instead use
prev()to select element which you want to hideDemo
Updated as per comment:
You can use this code:
Live Demo