“JS Wstaw po elemencie” Kod odpowiedzi

JS Wstaw po elemencie

var d1 = document.getElementById('one');
d1.insertAdjacentHTML('afterend', '<div id="two">two</div>');
Borma

Wstaw element po elemencie JavaScript


        
            
        
     function insertAfter(newNode, existingNode) {
    existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
}
Clean Crane

JS Wstaw po elemencie

<!DOCTYPE html>
<html>
<body>
     <p id='up'>Up</p>
    <p id="down">Down</p>
  <button id="switchBtn" onclick="switch_place()">Switch place</button>
  <script>
    function switch_place(){
      var downElement = document.getElementById("down")
      var upElement = document.getElementById("up")
      downElement.after(upElement);
      document.getElementById('switchBtn').innerHTML = "Switched!"
    }
  </script>
</body>
</html>
Borma

JavaScript Element po

function insertAfter(newNode, existingNode) {
    existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
}
VasteMonde

Odpowiedzi podobne do “JS Wstaw po elemencie”

Pytania podobne do “JS Wstaw po elemencie”

Więcej pokrewnych odpowiedzi na “JS Wstaw po elemencie” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu