Dan Marks
Dan Marks

Reputation: 49

Snap.svg changing colour attr

I am trying to learn how to use snap.svg and I am currently trying to change the colour of a part of my svg. However everytime I try this the page goes blank and i get the error (Uncaught TypeError: Cannot read property 'attr' of null) This is my

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Test</title>
    <script src="dist/snap.svg.js"></script>
</head>
<body>
<script>
    var s = Snap(800,600);
    var g = s.group();
    var cube = Snap.load("theCube2.0.svg", function ( f ) {

        var g = f.select("SVGID_2_");
        g.attr({fill: '#101010'});
        s.append( f );
    } );


</script>

I have also linked my svg. https://dl.dropboxusercontent.com/u/185556553/theCube2.0.svg

Upvotes: 0

Views: 1027

Answers (1)

Tamil Selvan C
Tamil Selvan C

Reputation: 20209

You forgot to mention the css selector #SVGID_2_ not SVGID_2_

Use

var g = f.select("#SVGID_2_"); 

syntax:

f.selector("css selector")

Upvotes: 1

Related Questions