jQuery html() 메서드

❮ jQuery HTML/CSS 메소드

예시

모든 <p> 요소의 내용을 변경합니다.

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

정의 및 사용

html() 메서드는 선택한 요소의 내용(innerHTML)을 설정하거나 반환합니다.

이 메서드를 사용하여 콘텐츠를 반환하는 경우 FIRST 일치 요소의 콘텐츠를 반환합니다 .

이 방법을 사용하여 내용을 설정 하면 일치하는 모든 요소의 내용을 덮어씁니다.

팁: 선택한 요소의 텍스트 내용만 설정하거나 반환하려면 text() 메서드를 사용합니다.


통사론

반환 내용:

$(selector).html()

콘텐츠 설정:

$(selector).html(content)

기능을 사용하여 콘텐츠 설정:

$(selector).html(function(index,currentcontent))

Parameter Description
content Required. Specifies the new content for the selected elements (can contain HTML tags)
function(index,currentcontent) Optional. Specifies a function that returns the new content for the selected elements
  • index - Returns the index position of the element in the set
  • currentcontent - Returns the current HTML content of the selected element

직접 해보십시오 - 예


의 내용을 반환하는 방법입니다.


을 사용하여 선택한 모든 요소의 내용을 설정합니다.


❮ jQuery HTML/CSS 메소드