DOM Samples /Core NamedNodeMap/setNamedItem()

It – Hardware & Software | | 3 views

J avaScript Samples
Dom compilation


DOM1 | DOM2 | DOM3 setNamedItem () explanation: The node which is appointed by argument is added.In case of existing name the interface which replaces: /Core/ NamedNodeMap Syntax: oj.setNamedItem (arg) argument:

name The node which it should set

Return value: When it replaces, the existing node.When it inserts anew, null is returned.
Exception:

WRONG_DOCUMENT_ERR When this node was drawn up, occurrence to the case where newChild was drawn up from the document which differs
NO_MODIFICATION_ALLOWED_ERR This node and occurrence to the case where it is read-only
NOT_FOUND_ERR With the Attr instance a where argument arg is used already in the other element the re occurrence.Even if when you set to the element which differs even in attribute of the same meaning, it is necessary each one separately to draw up attribute

Remark:

    table legend of browser behavior Win n7 — Netscape Navogator 7.x m1 — Mozilla1.x (Mozilla,FireFox) e6 — Internet Explorer 6.x o7 — Opera 7.x Mac n7 — Netscape Navogator 7.x m1 — Mozilla1.x e5 — Internet Explorer 5.0 or 5.1 s1 — Safari Linux n7 — Netscape Navogator 7.x m1 — Mozilla1.x k3 — Konqueror 3.x

sample : 1 browser behavior

win mac linux
n7 m1 e6 o7 n7 m1 e5 s1 n7 m1 k3
×

<script type=”text/javascript”> <!– function setTest() { /1 idname istestImgvariable elements of theimgadd to img = document.getElementById(‘testImg’) /2 widthvariable to generate the attributes of a namedattriadd to attri = document.createAttribute(“width”) /3 widthan attribute nodeimgis set to map alert(img.attributes. setNamedItem(attri) ) /4 is setwidthwrite a value to an attribute img.setAttribute(“width”,”200″) } /–> </script> <img id = “testImg” height = “60″ src = “/img.allabout.co.jp/gm/article/24088/usa.gif”> <form> <input type = “button” value = “test” onclick = “setTest()”> </form>
sample and the imagewidthset an attribute node, rewrite the value.
sample : 2 browser behavior

win mac linux
n7 m1 e6 o7 n7 m1 e5 s1 n7 m1 k3

-on the link belowiframeto output
-output to the new window on the link below
-on the link belowselfto output window sample1
sample2

<script type=”text/javascript”> <!– function chgTargets(targetName) { /1 testAsinAover all the elements to the node list as = document.getElementById(“testAs”).getElementsByTagName(“A”) /2allAthe elements in order to be processed for ( i=0 ; i < as.length ; i++ ) { /2_1 targetto generate the attribute variableattriadd to attri = document.createAttribute(“target”) /2_2 as.item(i) totargetto add an attribute as.item(i).attributes. setNamedItem(attri) /2_3 targetattribute is set as.item(i).setAttribute(“target”,targetName) } } /–> </script> <form> <input type = “radio” name = “swt” onclick = “chgTargets(‘ifr0′)”>-on the link belowiframeto output<br> <input type = “radio” name = “swt” onclick = “chgTargets(‘_blank’)”>-output to the new window on the link below<br> <input type = “radio” name = “swt” onclick = “chgTargets(‘_self’)”>-on the link belowselfto output window </form> <div id=”testAs”> <a href = “./test.htm”>sample1</a><br> <a href = “./test.htm”>sample2</a><br> </div> <br> <br> <iframe name=”ifr0″></iframe>
in this sample Ain the tagtargetwe rewrite the attribute.
sample : 3 browser behavior

win mac linux
n7 m1 e6 o7 n7 m1 e5 s1 n7 m1 k3
× ×
  1. list1
  2. list2
  3. list3
  4. list4