본문 바로가기

sundries

3-4 attr()

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

<script src ="../js/jquery-3.2.1.js"></script>

</head>

<!--  attr(속성명)메서드 : 속성의 값을 알아낼 수 있음 

img 태그가 3개인데 출력값은?

첫번 쨰 문서 객체의 속성을 출력 

-->

<script>

$(function(){

var src = $('img').attr('src');

alert(src)

});


</script>

<body>

<img src = "../image/smile_01.png" >

<img src = "../image/smile_04.png" >

<img src = "../image/smile_05.png" >

</body>

</html>



<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

<script src ="../js/jquery-3.2.1.js"></script>

</head>

<!--  attr(속성명)메서드 : 속성의 값을 알아낼 수 있음 

img 태그가 3개인데 출력값은?

첫번 쨰 문서 객체의 속성을 출력 

-->

<script>

$(function(){

$('img').each(function(index, item){

alert("index= "+ index + " , "

+ $(item).attr('src'));

})

});

</script>

<body>

<img src = "../image/smile_01.png" >

<img src = "../image/smile_04.png" >

<img src = "../image/smile_05.png" >

</body>

</html>





<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

<script src ="../js/jquery-3.2.1.js"></script>

</head>

<script>

$(function(){

$('img').attr('width',200);

});

</script>

<body>    

<img src = "../image/smile_01.png" >

<img src = "../image/smile_04.png" >

<img src = "../image/smile_05.png" >

</body>

</html>