1

I created a SVG path using snap.svg you can see the code of it down bellow. Now I am trying to cdhange the value of the Attributes for example the strokeWidth. For this i created a text input box and a button that runs a function which should fill in a new value for the strokeWidth. But it does not work. What am i doing wrong? Is it possible that i can't even change the value ? I also posted the code for the input box and the button + my function for changing the strokewidth down bellow

I tried a lot of different functions and scripts but none seemed to work. Sometimes I got an error message sometimes not. When i got an error message it always said that either the function is not defined or L_PUF_WAR is not defined.

var L_PUF_WAR = s.path("m 937.88689,516.10127 v -51.8831 H 573.37482 V 340.49692 H 391.11879 V 276.6408").attr({
                        fill: "none",
                        stroke: "#bada55",
                        strokeWidth: 15,
                        strokeDasharray: "30, 30 ,30"
                    });
                    A_PUF.append(L_PUF_WAR);```       

    <script>
        function hallo(){
            var number = document.getElementById("number").value;
            if(number > 0){
                L_PUF_WAR.strokeWidth = number;
            }
        }
    </script>
        <input type="text" id="number" name="number"/><br/>  
        <input type="button" value="breite" onclick="hallo()"/> 

I am expecting to put in a value for the strokewidth into the Input Box for example 20 and then the strokeWidth should change to that value..

1 Answers1

0

Try using .setAttribute():

L_PUF_WAR.setAttribute("strokeWidth", number);
Chris Pickford
  • 8,642
  • 5
  • 42
  • 73