JavaScript - setAttributeNS() method

revision:


Category : element

setAttributeNS() methof adds a new attribute or changes the value of an attribute with the given namespace and name.

Syntax :

        setAttributeNS(namespace, name, value)
    

Parameters:

namespace : a string specifying the namespace of the attribute.

name : a string identifying the attribute by its qualified name; that is, a namespace prefix followed by a colon followed by a local name.

value : the desired string value of the new attribute.

Examples:

            let d = document.getElementById("d1");
            d.setAttributeNS(
              "http://www.mozilla.org/ns/specialspace",
              "spec:align",
              "center"
            );
        

Practical examples

example:
code:
                    
                

example:
code:
                    
                

example:
code: