Reputation: 11911
I have this code:
$("#communities .inventory-search button.dropdown-toggle").on("click", function () {
$(".inventory-search .dropdown-toggle img").toggle();
});
This works, but it keeps toggling all the .dropdown-toggle
img items, how do I just target the one that was clicked?
Upvotes: 1
Views: 37
Reputation: 67525
You should use $(this)
instead to refer to the current clicked element like:
$("img", this).toggle();
//Or
$(this).find("img").toggle();
Else all the images inside .dropdown-toggle
will be toggled on click not just the clicked one, full code will be :
$("#communities .inventory-search button.dropdown-toggle").on("click", function () {
$("img", this).toggle();
});
Hope this helps.
Upvotes: 2
Reputation: 4065
You should be able to do something like:
$("#communities .inventory-search button.dropdown-toggle").on("click", function () {
$(this).find("img").toggle();
});
Upvotes: 1