Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
39
rated 0 times [  41] [ 2]  / answers: 1 / hits: 45654  / 13 Years ago, mon, july 25, 2011, 12:00:00

Here is the SVG path:


<svg xmlns="http://www.w3.org/2000/svg" version="1.1" id="sss" viewBox="0 0 500 300">
<path id="s3" d="M 10,90 Q 100,15 200,70 Z"/>
</svg>

How can I change the d value?


Why does alert(document.getElementById('s3').d); give me undefined?


More From » html

 Answers
149

Attributes can be set another way:



alert(document.getElementById('s3').getAttribute('d'));


That seems to work. To set use setAttribute.



There is a difference between attributes and properties. Attributes are set like <elem attr='value'> and properties are dynamically set.



For example, an input element will not change its attribute when entering something in it. The property, however, will change. So .value would return the correct result, whereas .getAttribute('value') would return the initial value as set with value=something.



In your case, it's an explicit attribute and not a property. Hence, .d does not work whilst .getAttribute('d') does.



http://jsfiddle.net/Kdp4v/


[#91026] Friday, July 22, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aleenamarinr

Total Points: 610
Total Questions: 109
Total Answers: 118

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
;