jQuery prependTo() 메서드
예시
각 <p> 요소의 시작 부분에 <span> 요소를 삽입합니다.
$("button").click(function(){
$("<span>Hello World!</span>").prependTo("p");
});
정의 및 사용
prependTo() 메서드는 선택한 요소의 시작 부분에 HTML 요소를 삽입합니다.
팁: 선택한 요소의 끝에 HTML 요소를 삽입하려면 appendTo() 메소드를 사용하십시오.
통사론
$(content).prependTo(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 at the beginning of the selected elements. |
selector | Required. Specifies on which elements to prepend the content to |
직접 해보십시오 - 예
prependTo() 메서드를 사용하여 선택한 각 요소의 시작 부분에 기존 요소를 삽입하는 방법입니다.