Majid Fouladpour Majid Fouladpour - 1 year ago 103
Javascript Question

jQuery attr() fails to set attribute

I am trying to rotate an image via svg's

. This is the code I have:

<svg width="100" height="100">
<image id="trns" transform="rotate(90,50,50)" width="100" height="100" xlink:href="logo.png"/>

This successfully rotates
by 90 degrees when the page loads. Also, when I change
to a different number in firbug's HTML tab the rotation changes accordingly. But when I try to change the value with jQuery, nothing happens:

$('#trns').attr('transform', 'rotate(60, 50,50)');

What does firebug do that my
line does not?

Answer Source

Working fine here (with jQuery 1.6.2):

Make sure to call it once the DOM is ready:

 $('#trns').attr('transform', 'rotate(60,50,50)');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download