Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

도도의 IT이야기

[jQuery] 콘텐트 제거 그리고 attribute 바꾸기 본문

IT/자바스크립트

[jQuery] 콘텐트 제거 그리고 attribute 바꾸기

도도버드 2020. 5. 12. 01:59

.empty()는 innerHTML을 지움.

.remove()는 어떠한 element를 아예 없앰.

 

<p>hi I am dodo</p>
$('p').empty()//결과 <p></p>

$('p').remove()//결과: 없어짐

 

이제 element의 attribute을 제거하거나 바꾸는 방법을 알아보자

 

<div class="banner">

</div>

이러한 html이 있다고 해보자

 

.removeAttr()은 받은 인자로 받은 attribute을 완전히 지운다.

$('div').removeAttr('class')//결과: <div></div>

.attr 은 attribute의 값을 바꾸거나 return한다.

$('div').attr('class','anotherBanner'); //결과: <div class="anotherBanner"></div>

$('div').attr('class');// anotherBanner을 리턴함

'IT > 자바스크립트' 카테고리의 다른 글

[jQuery] 이벤트 바인딩  (0) 2020.05.12
[jQuery] CSS/class 바꾸는 방법  (0) 2020.05.12
[jQuery]wrap, unwrap,wrapAll  (0) 2020.05.12
[jQuery] html에 element를 더하고 바꾸는 방법  (0) 2020.05.12
[jQuery] jquery chaining  (0) 2020.05.11