jQuery insertBefore() 메서드

❮ jQuery HTML/CSS 메소드

예시

각 <p> 요소 앞에 <span> 요소를 삽입합니다.

$("button").click(function(){
  $("<span>Hello world!</span>").insertBefore("p");
});

정의 및 사용

insertBefore() 메서드는 선택한 요소 앞에 HTML 요소를 삽입합니다.

팁: 선택한 요소 뒤에 HTML 요소를 삽입하려면 insertAfter() 메소드를 사용하십시오.


통사론

$(content).insertBefore(selector)

Parameter Description
content Required. Specifies the content to insert (must contain HTML tags).

Note: If content is an existing element, it will be moved from its current position, and inserted before the selected elements.
selector Required. Specifies where to insert the content

직접 해보십시오 - 예


insertBefore() 메서드를 사용하여 선택한 각 요소 앞에 기존 요소를 삽입하는 방법입니다.


❮ jQuery HTML/CSS 메소드