Element-removeAttribute.html (2138B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Element.prototype.removeAttribute</title> 4 <link rel=help href="https://dom.spec.whatwg.org/#dom-element-removeattribute"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 8 <script> 9 "use strict"; 10 11 test(() => { 12 13 const el = document.createElement("p"); 14 el.setAttribute("x", "first"); 15 el.setAttributeNS("foo", "x", "second"); 16 17 assert_equals(el.attributes.length, 2); 18 assert_equals(el.getAttribute("x"), "first"); 19 assert_equals(el.getAttributeNS(null, "x"), "first"); 20 assert_equals(el.getAttributeNS("foo", "x"), "second"); 21 22 // removeAttribute removes the first attribute with name "x" that 23 // we set on the element, irrespective of namespace. 24 el.removeAttribute("x"); 25 26 // The only attribute remaining should be the second one. 27 assert_equals(el.getAttribute("x"), "second"); 28 assert_equals(el.getAttributeNS(null, "x"), null); 29 assert_equals(el.getAttributeNS("foo", "x"), "second"); 30 assert_equals(el.attributes.length, 1, "one attribute"); 31 32 }, "removeAttribute should remove the first attribute, irrespective of namespace, when the first attribute is " + 33 "not in a namespace"); 34 35 test(() => { 36 37 const el = document.createElement("p"); 38 el.setAttributeNS("foo", "x", "first"); 39 el.setAttributeNS("foo2", "x", "second"); 40 41 assert_equals(el.attributes.length, 2); 42 assert_equals(el.getAttribute("x"), "first"); 43 assert_equals(el.getAttributeNS("foo", "x"), "first"); 44 assert_equals(el.getAttributeNS("foo2", "x"), "second"); 45 46 // removeAttribute removes the first attribute with name "x" that 47 // we set on the element, irrespective of namespace. 48 el.removeAttribute("x"); 49 50 // The only attribute remaining should be the second one. 51 assert_equals(el.getAttribute("x"), "second"); 52 assert_equals(el.getAttributeNS("foo", "x"), null); 53 assert_equals(el.getAttributeNS("foo2", "x"), "second"); 54 assert_equals(el.attributes.length, 1, "one attribute"); 55 56 }, "removeAttribute should remove the first attribute, irrespective of namespace, when the first attribute is " + 57 "in a namespace"); 58 </script>