jQuery w3schools 한글판 강좌53 -Add Several New Elements With after() and before() 정보
jQuery jQuery w3schools 한글판 강좌53 -Add Several New Elements With after() and before()본문
jQuery w3schools 한글판 강좌53 -after(), before()를 이용한 각각의 새 요소 삽입하기
after()와 before() 메소드 역시 무한히 많은 새요소들을 매개변수로 취할수 있습니다.
새요소들은 text/HTML로 생성될수 있으며(이전의 예에서 보셨듯이), jQuery나 자바스크립트코드 그리고 DOM요소를 이용하여 생성할수도 있습니다.
다음 예에서는 각기 새 요소들을 생성합니다.
요소들은 text/HTML, jQuery, 그리고 JavaScript/DOM을 이용해서 생성됩니다.
그런후에 그 텍스트에 after()메소드를 이용하여 새 요소들을 삽입합니다.
(이 방법은 before()메소드도 같은 방식으로 사용가능합니다):
Example
function afterText() {
var txt1 = "<b>I </b>"; // HTML이용 요소 생성
var txt2 = $("<i></i>").text("love "); // jQuery 이용 생성
var txt3 = document.createElement("b"); // DOM 을 이용 생성
txt3.innerHTML = "jQuery!";
$("img").after(txt1, txt2, txt3); // <img>뒤에 새 요소들 삽입
}
추천
0
0
댓글 0개