sundries

3-11 css 메서드 콜백 함수

스티브 2018. 1. 12. 20:40

<!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(){

//배열 생성 - index 0 , 1,  2

var color =['red','blue','purple'];

// 문서 객체의 스타일을 변경

// css() 메서드에서 두 번째 매개변수에 함수를 사용해서 개별적으로

// 스타일 속성을 적용할 떄 사용

$('h1').css('color',function(index){

return color[index];

})

});

</script>

<body>

<h1>Header-0</h1>

<h1>Header-0</h1>

<h1>Header-0</h1>


</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(){

//배열 생성 - index 0 , 1,  2

var color =['red','blue','purple'];


$('h1').css({

'color': function(index){

return color[index];

},

'backgroundColor': 'black'

});

});

</script>

<body>

<h1>Header-0</h1>

<h1>Header-0</h1>

<h1>Header-0</h1>

</body>

</html>