jQueryを利用してボタンを押すと背景と文字が同時に変わるWEBを作成しています。
背景はうまく変更できたのですが、文字の色変更に苦戦しています。
どのように追加したら良いでしょうか?
宜しくお願いします。
(jQuery)
jQuery( function() { backgroundColor(); jQuery( '#backgroundColorCoral' ).click( function () { backgroundColor( 'coral' ); } ); jQuery( '#backgroundColorYellow' ).click( function () { backgroundColor( 'yellow' ); } ); jQuery( '#backgroundColorSkyblue' ).click( function () { backgroundColor( 'skyblue' ); } ); function backgroundColor( $backgroundColor ){ if( $backgroundColor == undefined ){ var $backgroundColor = jQuery.cookie( 'backgroundColor' ); if( $backgroundColor == undefined ){ var $backgroundColor = 'yellow'; } } jQuery( '#backgroundColor' ).html( $backgroundColor ); jQuery.cookie( 'backgroundColor', $backgroundColor, { expires: 1 } ); jQuery( '#sample' ).css( { 'backgroundColor': $backgroundColor } ); } } );
(html)
<div id="sample"><p> <span id="backgroundColorCoral">coral</span> <span id="backgroundColorYellow">yellow</span> <span id="backgroundColorSkyblue">skyblue</span> </p> </div>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/21 12:34
2018/09/21 12:45
2018/09/21 20:59