I have a set of divs which are specified under the same class name, and which have no ids. Given this scenario, how can I use Jquery’s .hide() method to hide only the div that was clicked, and not the entire class without having to specify an id for each div?
<div class="div"><p>Some placeholder text </p> </div>
<div class="div"><p>Some more placeholder text </p> </div>
<div class="div"><p>And even placeholder text </p> </div>
$(".div").click (function(){
$(".div").hide();
});
The script above will hide all divs with the class “div” but we only want to hide the div that was clicked, not the entire class.
This is what you are looking for: