웹 & 프레임워크

JavaScript Element 추가예제

늘근이 2014. 6. 27. 11:29

  function addElementNodeByTextNode(){

                                       

                                var h2 = document.createElement("h2"); //<h2></h2>

                                h2.appendChild(document.createTextNode("안녕?"));//<h2>안녕하세요</h2>

                                       

                                var page = document.getElementById("sample_page");

                                page.insertBefore(h2, page.firstChild);

                                        //여기 h2 스타일 주면 된다! 텍스트노드가 아니니까

 

                           }


Jquery도 좋지만, 자바스크립트도 모두 할수있는 기능이다