Jonas
Jonas

Reputation: 1

I have more than one svg in some boxes, I want to only change the color, on the one that I click

I have some svg's I want to change their fill on click, but I want it only change the color, on the one that I click, each svg have the same class and id's, but are in different divs/boxes

 $('svg').on("click", function() {
        $('.cls-1').css("fill","#8b5a0b");
 });

Upvotes: 0

Views: 16

Answers (1)

ilia
ilia

Reputation: 1333

You can use $(this) inside event handler to get the element on which the event was fired.

$('svg').on('click', function() {
  $(this).css('fill', '#8b5a0b');
});

Upvotes: 1

Related Questions