본문 바로가기

Local Oriented/jQuery

[모음글] attr 속성

$('...').attr('attrA') 속성값 조회

$('...').attr('attrA','valA') 속성값 설정

$('...').attr({'attrA':'valA', 'attrB':'valB', ..., 'attrZ':'valZ'}) 여러 속성값 설정

속성 삭제시, removePop() 사용


스타일 속성값은 attr 대신에 css 로 상기와 같이 조회/설정 할 수 있고,

스타일은 클래스 단위로 작업하는 것이 더 간단할 수 있으며..

hasClass(), addClass(), removeClass()


cf. prop() 과 removeProp() 은 checked, selected, disabled 등과 같이 boolean 으로 세팅되는 항목에 대하여 사용


속성에 대하여 true false 로 접근할 때는 pop() 계열,

속성에 대하여 그 값 그대로 접근할 때는 attr() 계열.

상기 내용은 버전별로 다르기 때문에..

<input type="radio" name="..." /> 에 대하여,

$('...').prop('checked') 라면 리턴값은 true 나 false,

$('...').attr('checked') 라면 리턴값은 'checked' 나 ''