자바스크립트는 insertAdjacentHTML()을 제공했습니다. 지정된 위치에 텍스트를 HTML로 삽입하는 메서드입니다. 해당 법적 위치는
-
이후 시작
-
후
-
시작하기 전에
-
전
각 법적 지위는 고유한 중요성을 가지고 있습니다. 그 중 몇 가지를 논의해 보겠습니다.
예시
다음 예에서는 "insertAdjacentHTML() " 방법과 법적 지위 "afterend ", 새 텍스트가 헤더에 인접하게 배치되고 결과가 출력에 표시됩니다.
<html>
<body>
<h2 id="H2">Header</h2>
<script>
var ins = document.getElementById("H2");
ins.insertAdjacentHTML("afterend","<p>Tutorix is the best e-learning platform</p>");
</script>
</body>
</html> 출력
Header
Tutorix is the best e-learning platform
예시
다음 예에서는 "insertAdjacentHTML() " 방법 및 법적 지위 "전 ", 새 텍스트가 헤더에 인접하게 배치되고 결과가 출력에 표시됩니다.
<html>
<body>
<h2 id="H2">Header</h2>
<script>
var ins = document.getElementById("H2");
ins.insertAdjacentHTML("beforeend","<p>Tutorix is the best e-learning platform</p>");
</script>
</body>
</html> 출력
Header
Tutorix is the best e-learning platform