Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <p>insertAdjacentElement:</p>
  <div><span id="a"> [Third] </span></div>
  <p>insertAdjacentText:</p>
  <div><span id="b"> [Third] </span></div>
</body>
</html>
 
function elem(text) {
  var el = document.createElement('span');
  try {
    el.textContent = text;
  } catch (err) {}
  try {
    el.innerText = text;
  } catch (err) {}
  return el;
}
window.onload = function () {
  var a = document.getElementById('a');
  try { a.insertAdjacentElement('beforebegin', elem('1st (out)')); } catch (e) {}
  try { a.insertAdjacentElement('afterbegin', elem('2nd (in)')); } catch (e) {}
  try { a.insertAdjacentElement('beforeend', elem('4th (in)')); } catch (e) {}
  try { a.insertAdjacentElement('afterend', elem('5th (out)')); } catch (e) {}
  
  var b = document.getElementById('b');
  try { b.insertAdjacentText('beforebegin', '1st (out)'); } catch (e) {}
  try { b.insertAdjacentText('afterbegin', '2nd (in)'); } catch (e) {}
  try { b.insertAdjacentText('beforeend', '4th (in)'); } catch (e) {}
  try { b.insertAdjacentText('afterend', '5th (out)'); } catch (e) {}
};
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
cvrebertpro
0viewers