カテゴリー︎: 【jQuery】
jQueryでcssを操作するおさらい
(サンプル例)
ボタンをクリックしてcssを変更する
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>jQueryのおさらい【cssを操作する】</title>
</head>
<body>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<style>
.text{
color: white;
background: green;
}
</style>
<button id="btn">クリックするとcssを変更する</button>
<p class="text">テスト</p>
<script>
$('#btn').click(function() {
var newcss = { 'color': '#tomato', 'fontSize': '30px', 'background': '#EA6D6D', 'padding': '10px' };
$('.text').css(newcss);
});
</script>
</body>
</html>
テスト
ボタンをクリックすることで、cssの設定を上書きできる