|
290 | 290 | testing.expectEqual("stylesheet", linkElement.rel); |
291 | 291 | </script> |
292 | 292 |
|
293 | | -<script id=insertAdjacentHTML> |
294 | | - const el4 = document.createElement("div"); |
295 | | - |
296 | | - const el5 = document.createElement("span"); |
297 | | - el4.appendChild(el5); |
298 | | - |
299 | | - const el6 = document.createElement("p"); |
300 | | - el6.innerText = "content"; |
301 | | - el4.appendChild(el6); |
| 293 | +<!-- This structure will get mutated by insertAdjacentHTML test --> |
| 294 | +<div id="insert-adjacent-html-outer-wrapper"> |
| 295 | + <div id="insert-adjacent-html-inner-wrapper"> |
| 296 | + <span></span> |
| 297 | + <p>content</p> |
| 298 | + </div> |
| 299 | +</div> |
302 | 300 |
|
303 | | - el5.insertAdjacentHTML("beforebegin", "<h1>title</h1>"); |
304 | | - testing.expectEqual("<h1>title</h1><span></span><p>content</p>", el4.innerHTML); |
| 301 | +<script id=insertAdjacentHTML> |
| 302 | + // Insert "beforeend". |
| 303 | + const wrapper = document.querySelector("div#insert-adjacent-html-inner-wrapper"); |
| 304 | + wrapper.insertAdjacentHTML("beforeend", "<h1>title</h1>"); |
| 305 | + let newElement = wrapper.lastElementChild; |
| 306 | + testing.expectEqual("H1", newElement.tagName); |
| 307 | + testing.expectEqual("title", newElement.innerText); |
| 308 | + |
| 309 | + // Insert "beforebegin". |
| 310 | + wrapper.insertAdjacentHTML("beforebegin", "<h2>small title</h2>"); |
| 311 | + newElement = wrapper.previousElementSibling; |
| 312 | + testing.expectEqual("H2", newElement.tagName); |
| 313 | + testing.expectEqual("small title", newElement.innerText); |
| 314 | + |
| 315 | + // Insert "afterend". |
| 316 | + wrapper.insertAdjacentHTML("afterend", "<div id=\"afterend\">after end</div>"); |
| 317 | + newElement = wrapper.nextElementSibling; |
| 318 | + testing.expectEqual("DIV", newElement.tagName); |
| 319 | + testing.expectEqual("after end", newElement.innerText); |
| 320 | + testing.expectEqual("afterend", newElement.id); |
| 321 | + |
| 322 | + // Insert "afterbegin". |
| 323 | + wrapper.insertAdjacentHTML("afterbegin", "<div class=\"afterbegin\">after begin</div><yy></yy>"); |
| 324 | + newElement = wrapper.firstElementChild; |
| 325 | + testing.expectEqual("DIV", newElement.tagName); |
| 326 | + testing.expectEqual("after begin", newElement.innerText); |
| 327 | + testing.expectEqual("afterbegin", newElement.className); |
305 | 328 | </script> |
0 commit comments