jQuery Attributes(요소의 속성) getter/setter

각 요소의 속성은 유용한 정보를 가지고 있기 때문에, 이것을 가지고 get/set 하는 것은 중요하다.

 

.attr() 메소드

.attr() 메소드로 getter/setter 작업 둘 다 할 수 있다.

 

.attr() setter:

1
2
3
4
5
6
7
8
9
10
11
12
13
$( "a" ).attr( "href""allMyHrefsAreTheSameNow.html" );
 
 
 
$( "a" ).attr({
 
    title: "all titles are the same too!",
 
    href: "somethingNew.html"
 
});
 
cs

 

.attr() getter:

1
$( "a" ).attr( "href" ); // Returns the href for the first a element in the document
cs

 

 

 

http://learn.jquery.com/using-jquery-core/attributes/

+ Recent posts