반응형
[jQuery] attr 메소드
attribute-1.html |
<!doctype html> <html lang="ko"> <head> <meta charset="UTF-8"> <title>attr 메소드</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script> <script type="text/javascript"> jQuery(document).ready(function() { // jQuery("선택자").attr("속성") => 속성값을 반환 받는 메소드 alert("파일명 = " + jQuery("img").attr("src")); // jQuery("선택자").attr("속성", "변경값") => 속성값을 변경 하는 메소드 jQuery("img").attr("width", "400px"); jQuery("img").attr("height", "300px"); }); </script> </head> <body> <h1>attr 메소드</h1> <hr/> <img src="images/Penguins.jpg"> </body> </html> |
출력결과 |
attribute-2.html |
<!doctype html> <html lang="ko"> <head> <meta charset="UTF-8"> <title>attr 메소드</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script> <script type="text/javascript"> jQuery(document).ready(function() { // jQuery("선택자").attr("속성") => 속성값을 반환 받는 메소드 alert("파일명 = " + jQuery("img").attr("src")); // jQuery("선택자").attr("속성", "변경값") => 속성값을 변경 하는 메소드 jQuery("img").attr("width", "400px").attr("height", "300px"); }); </script> </head> <body> <h1>attr 메소드</h1> <hr/> <img src="images/Koala.jpg"> </body> </html> |
출력결과 |
attribute-3.html |
<!doctype html> <html lang="ko"> <head> <meta charset="UTF-8"> <title>attr 메소드</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script> <script type="text/javascript"> jQuery(document).ready(function() { // jQuery("선택자").attr("속성") => 속성값을 반환 받는 메소드 alert("파일명 = " + jQuery("img").attr("src")); // jQuery("선택자").attr("속성", "변경값") => 속성값을 변경 하는 메소드 jQuery("img").attr({ "width" : "400px" , "height" : "300px" }); }); </script> </head> <body> <h1>attr 메소드</h1> <hr/> <img src="images/Tulips.jpg"> </body> </html> |
출력결과 |
반응형
'jQuery' 카테고리의 다른 글
[jQuery] jQuesy 이벤트 (0) | 2015.12.20 |
---|---|
[jQuery] text 메소드와 html 메소드 (0) | 2015.12.20 |
[jQuery] css 메소드 (0) | 2015.12.20 |
[jQuery] each 메소드 (0) | 2015.12.20 |
[jQuery] eq 선택자 (0) | 2015.12.20 |