본문 바로가기
WWWEB/Script

javascript로 style 삭제 방법

by 미니토이 2023. 1. 2.

javascript로 html에 인라인 스타일로 들어가 있는 style을 삭제하려고 찾아보니

여러가지 다양한 방법을 찾을 수 있었다.

 

아래 코드들을 통해 정리해봄.

 

 

1. removeProperty()

document.querySelector( 'button' ).onclick = function(){
    const obj = document.getElementById( 'container' );
    obj.style.removeProperty( 'border' );
}

 

 

 

2. 빈 문자열

document.querySelector( 'button' ).onclick = function() {
    const obj = document.getElementById( 'container' );
    obj.style.border = '';
}

 

 

 

3. removeAttribute()

document.querySelector( 'button' ).onclick = function() {
    document.getElementById('container' ).removeAttribute( 'style' );
}

 

 

728x90
반응형

댓글