sc0ttj / component

A tiny library for isomorphic JavaScript components
MIT License
2 stars 1 forks source link

Fix: svg templating with `html` and `htmel` #23

Closed sc0ttj closed 3 years ago

sc0ttj commented 3 years ago

Add some fixes for html and htmel that allow full support for SVGs.

See:

Once you have selected an SVG element, you can get and set its attributes with getAttributeNS() and setAttributeNS(). For example, we can get an element's y coordinate and add 10 to it like so:

var y = parseFloat(element.getAttributeNS(null, 'y'));
element.setAttributeNS(null, 'y', y + 10);

This will work regardless how the SVG is added to the page or where the JS is.

Note that these functions are slightly different from the standard getAttribute and setAttribute methods because the elements are not HTML elements, rather in the SVG namespace (NS stands for namespace). This means you have to pass an additional parameter to each method, which can just be null.