element.setAttributeNodeNS

<breadcrumbs></breadcrumbs>

== Summary ==

ๆฆ‚่ฆ

<code>setAttributeNodeNS</code> adds a new attribute node with the specified namespace and name. setAttributeNodeNS ใฏๆŒ‡ๅฎšใฎๅๅ‰็ฉบ้–“ใจๅๅ‰ใงๆ–ฐใ—ใ„ๅฑžๆ€งใƒŽใƒผใƒ‰ใ‚’่ฟฝๅŠ ใ—ใพใ™ใ€‚== Syntax ==

ๆง‹ๆ–‡

replacedAttr = element.setAttributeNodeNS(attributeNode)

* <code>replacedAttr</code> is the replaced attribute node, if any, returned by this function. * <code>attributeNode</code> is an <code>Attr</code> node.

  • replacedAttr ใฏใ€ใ“ใฎ้–ขๆ•ฐใซใ‚ˆใฃใฆ่ฟ”ใ•ใ‚Œใ‚‹ใฎใงใ‚ใ‚Œใฐใ€็ฝฎใๆ›ใˆใ‚‰ใ‚ŒใŸๅฑžๆ€งใƒŽใƒผใƒ‰ใงใ™ใ€‚
  • attributeNode ใฏ Attr ใƒŽใƒผใƒ‰ใงใ™.

Example

// <div id="one" special-align="utterleft">one</div>
// <div id="two">two</div>

var myns = "http://www.mozilla.org/ns/specialspace";
var d1 = document.getElementById("one");
var d2 = document.getElementById("two");
var a = d1.getAttributeNodeNS(myns, "special-align");
d2.setAttributeNodeNS(a);

alert(d2.attributes[1].value) // returns: `utterleft'

ๆณจ่จ˜

If the specified attribute already exists on the element, then that attribute is replaced with the new one and the replaced one is returned. ๆŒ‡ๅฎšใฎๅฑžๆ€งใŒๆ—ขใซๅญ˜ๅœจใ—ใฆใ„ใ‚‹ใจใใฏใ€ใใฎๅฑžๆ€งๆ–ฐใ—ใ„ใ‚‚ใฎใซ็ฝฎใๆ›ใˆใ‚‰ใ‚Œใ€็ฝฎใๆ›ใˆใ‚‰ใ‚ŒใŸใ‚‚ใฎใŒๆˆปใ‚Šๅ€คใจใ—ใฆ่ฟ”ใ•ใ‚Œใพใ™ใ€‚

DOM ใƒกใ‚ฝใƒƒใƒ‰ใฏ่ฆ็ด ใฎๅฑžๆ€งใ‚’ๅ–ใ‚Šๆ‰ฑใ„ใพใ™ใ€‚

ๅๅ‰็ฉบ้–“ใซ็„ก้–ขไฟ‚ใ€
ๆœ€ใ‚‚ไธ€่ˆฌ็š„ใซไฝฟ็”จใ•ใ‚Œใ‚‹ใƒกใ‚ฝใƒƒใƒ‰
ๅๅ‰็ฉบ้–“ใซ้™ๅฎšใ•ใ‚Œใ‚‹ๅค‰ๆ•ฐ
(DOM Level 2)
Attr ใƒŽใƒผใƒ‰ใ‚’็›ดๆŽฅๆ‰ฑใ† DOM ใƒฌใƒ™ใƒซ 1 ใฎใƒกใ‚ฝใƒƒใƒ‰
(ใปใจใ‚“ใฉไฝฟ็”จใ•ใ‚Œใชใ„)
Attr ใƒŽใƒผใƒ‰ใ‚’็›ดๆŽฅๆ‰ฑใ† DOM ใƒฌใƒ™ใƒซ 2 ๅๅ‰็ฉบ้–“ใซ้™ๅฎšใ•ใ‚Œใ‚‹ใƒกใ‚ฝใƒƒใƒ‰
(ใปใจใ‚“ใฉไฝฟ็”จใ•ใ‚Œใชใ„)
setAttribute (DOM 1) setAttributeNS setAttributeNode setAttributeNodeNS
getAttribute (DOM 1) getAttributeNS getAttributeNode getAttributeNodeNS
hasAttribute (DOM 2) hasAttributeNS - -
removeAttribute (DOM 1) removeAttributeNS removeAttributeNode -
== Specification ==

ไป•ๆง˜

DOM Level 2 Core: setAttributeNodeNS