0

So I've read through a lot of questions, but none have worked for me so far.

      <svg height="100%" width="100%" class="myclass">
        <polygon points="0,0 513,0 0,513" style="fill:red;" />
      </svg>

So my svg is the color red. However, I want to change the fill to an image.

The twist is, I want to be able to override this image. For example, onClick change the background image of the SVG.

I've been struggling.

Thanks!

pourmesomecode
  • 4,108
  • 10
  • 46
  • 87

1 Answers1

0

Try this https://jsfiddle.net/2Lzo9vfc/62/

HTML

<svg height="100%" width="100%" class="hover">
   <polygon class="shape" points="0,0 513,0 0,513" style="fill :red;" />
</svg>

<svg height="100%" width="100%" class="click">
   <polygon class="shape" points="0,0 513,0 0,513" style="fill :red;" />
</svg>

JS

$('.hover').hover(function(){
  $(this).find('polygon').css('fill', 'black');
},function(){
    $(this).find('polygon').css('fill', 'red');
});

$('.click').click(function() {
    $(this).find('polygon').css('fill', 'black');
});

First example is change on hover second one is on click.

Nenad Vracar
  • 118,580
  • 15
  • 151
  • 176