jQuery before() 메서드
예시
각 <p> 요소 앞에 내용 삽입:
$("button").click(function(){
$("p").before("<p>Hello world!</p>");
});
정의 및 사용
before() 메서드는 선택한 요소의 앞에(앞에) 지정된 내용을 삽입합니다.
팁: 선택한 요소 뒤에 내용을 삽입하려면 after() 메서드를 사용하십시오.
통사론
$(selector).before(content,function(index))
Parameter | Description |
---|---|
content | Specifies the content to insert (can contain HTML tags)
Possible values:
|
function(index) | Optional. Specifies a function that returns the content to insert
|
직접 해보십시오 - 예
before() 메서드로 콘텐츠를 삽입합니다.
를 사용하여 내용 삽입하기 기능을 사용하여 선택한 요소 앞에 내용을 삽입하는 방법입니다.