반응형
Getting attribute of a parent node $(this).parentNode.attr('class')
jquery와 plain javascript를 섞어 섰다는것..
java 사용해서 백엔드단만 작업하다보니 전혀 생각못했던 부분이었다..
jquery를 사용하는곳이 아직 많기 때문에 해당부분을 유의해서 코드작업을 해야할것 같다.
// jQuery
$(this).parent().attr('class');
// Vanila Javascript
this.parentNode.getAttribute("class");
attr() 메서드와 getAttribute()메서드
.attr() 메서드
.attr(attributeName)
.attr(attributeName,value)
선택한요소의 속성의 값을 가져오거나 속성을 추가한다.
$( '#id' ).attr( 'class' );
$( '#id' ).attr( 'class','on' );
.getAttribute()
.getAttribute('attributeName')
선택한요소의 속성의 값을 가져온다.
var attr = document.getElementById( 'id' ).getAttribute( 'class' );
.setAttribute()
.setAttribute('attributeName','value')
선택한요소의 속성의 값을 추가한다.
document.getElementById( 'id' ).setAttribute( 'class', 'on' )
Reference
반응형
'WEB > Error' 카테고리의 다른 글
[TypeScript] 'tsc'은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는배치 파일이 아닙니다 (0) | 2023.09.30 |
---|---|
[JAVA] the method is undefined for the type (0) | 2022.02.09 |
[GitHub] remote: Support for password authentication was removed on August 13, 2021. Plea.. (0) | 2021.12.24 |
[MAVEN] Cannot load JDBC driver class 'org.mariadb.jdbc.Driver' (0) | 2021.06.24 |
[HTML] 마크업 유효성 검사 (0) | 2020.10.26 |