<分区>
标签 javascript jquery html css
<分区>
我想在单击按钮时更改“游戏添加”按钮的背景颜色。当在叠加层中单击“X”时,我想将其改回以前的颜色。这是我的代码
$('.game-add').click(function() {
$(".game-add").css("background-color","5da93c");
$('#overlay').toggleClass('active');
// calcs bottom of button
var bottom = $(this).position().top + $(this).outerHeight(true);
$('#overlay').css({
'top': bottom + 'px',
});
});
$('#close').click(function(){
$(".game-add").css("background-color","1D1D1D");
$('#overlay').removeClass('active');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" class="btn btn-link game-add">ADD GAME</button>
<div id="overlay">
<a href="#" id="close" class="pull-right" style="color: #fff;">X</a>
<h2>This is an overlay</h2>
</div>
任何帮助将不胜感激。谢谢你
最佳答案
您忘记了 #
哈希/数字符号,因此无法识别颜色。
// Code above
$('.game-add').click(function() {
$(this).css("background-color","#5da93c");
$('#overlay').toggleClass('active');
// The rest of the code
关于javascript - 单击按钮更改背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45587093/