P

jQuery w3schools 한글판 강좌53 -Add Several New Elements With after() and before()

· 2017-03-29 (수) 00:29:16 · 2181

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>뒤에 새 요소들 삽입
}

 

|
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

5,403건

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
PHP 17-04-04 조회 2,366
PHP 17-04-04 조회 2,867
jQuery 17-04-03 조회 1,779
jQuery 17-04-03 조회 2,303
jQuery 17-04-03 조회 1,867
node.js 17-03-29 조회 3,893
jQuery 17-03-29 조회 2,182
jQuery 17-03-29 조회 2,142
jQuery 17-03-29 조회 2,042
jQuery 17-03-28 조회 2,095
jQuery 17-03-28 조회 2,483
PHP 17-03-28 조회 2,306
PHP 17-03-28 조회 1,913
PHP 17-03-28 조회 2,113
jQuery 17-03-27 조회 3,218
jQuery 17-03-27 조회 1,879
jQuery 17-03-27 조회 1,775
jQuery 17-03-26 조회 2,143
jQuery 17-03-26 조회 2,097
jQuery 17-03-26 조회 2,278
jQuery 17-03-23 조회 2,071
jQuery 17-03-23 조회 2,030
jQuery 17-03-23 조회 2,020
jQuery 17-03-22 조회 2,087
jQuery 17-03-22 조회 2,305
jQuery 17-03-22 조회 1,954
jQuery 17-03-20 조회 2,134
jQuery 17-03-20 조회 2,390
jQuery 17-03-20 조회 1,957
jQuery 17-03-18 조회 2,282