IT/jQuery
jQuery - jQuery를 사용하여 css 적용하는 방법
노마드오브
2018. 10. 12. 20:54
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
var color = ['red', 'blue', 'purple'];
var c = $('h1').css('color');
//alert(c);
//$('h1').css('color', 'yellow');
// $('h1').css('color', function (index) {
// return color[index];
// });
$('h1').css({
color: function (index) {
return color[index]
},
backgroundColor: 'black'
});
});
</script>
</head>
<body>
<h1>head-0</h1>
<h1>head-1</h1>
<h1>head-2</h1>
</body>
</html>