tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

insert-adjacent.html (985B)


      1 <!doctype html>
      2 <title>insertAdjacentHTML</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <style>
      6 #element {
      7  display: none;
      8 }
      9 </style>
     10 
     11 <div id="element"></div>
     12 <div id="log"></div>
     13 
     14 <script>
     15 function wrap(text) {
     16  return '<h3>' + text + '</h3>';
     17 }
     18 
     19 var possiblePositions = {
     20    'beforebegin': 'previousSibling'
     21  , 'afterbegin': 'firstChild'
     22  , 'beforeend': 'lastChild'
     23  , 'afterend': 'nextSibling'
     24 }
     25 
     26 var el = document.querySelector('#element');
     27 
     28 Object.keys(possiblePositions).forEach(function(position) {
     29  var html = wrap(position);
     30  test(function() {
     31    el.insertAdjacentHTML(position, html);
     32    var heading = document.createElement('h3');
     33    heading.innerHTML = position;
     34    assert_equals(el[possiblePositions[position]].nodeName, "H3");
     35    assert_equals(el[possiblePositions[position]].firstChild.nodeType, Node.TEXT_NODE);
     36  }, 'insertAdjacentHTML(' + position + ', ' + html + ' )');
     37 });
     38 </script>