So, in dom like this
<div>
<button>Click me</button>
<img src=#>
</div>
<div>
<button>Click me</button>
<img src=#>
</div>
<div>
<button>Click me</button>
<img src=#>
</div>
And script
$("button").click(function() {img.hide() });
How to make js to be executed only in div which contains clicked button? dom is generated, so we cant use specific classes or id's
You can use parent() and find() methods.
$("button").click(function () {
$(this).parent().find('img').hide()
});
Or next() method like following.
$("button").click(function () {
$(this).next('img').hide()
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With