ドロップダウンフォームからオプションを選択したときに、attr()jQueryメソッドを使用してh1要素のクラス名を変更しようとしています。クラス名を変更して別のCSSプロパティ(フォント)にアクセスするようにしますクラス名を変更するjQuery attr()メソッド
私はDOMをさらに深く掘り下げてクラスを変更するつもりはないと思いますか?
$('h1').attr('class', fontChange);
function myFontStyle() {
$('#font').on("change", function() {
var fontChange = this.value
//console.log(this.value);
$('h1').attr('class', fontChange);
console.log('h1 has now class: ', $('h1').attr('class'))
});
}
myFontStyle();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label for="font">Choose font</label>
<select name="font" id="font">
<option value="handwriting">Handwriting</option>
<option value="sketch">Sketch</option>
<option value="print">Print</option>
</select>
<div class="card celadonBackground">
<div id="coverImage">
<img src="assets/birthday.jpg"/>
</div>
<div class="noBorder">
<h1 class="sketch">Happy birthday to you</h1>
</div>
</div>
を形成?それなしで書く –