[英]changing css background-color property
I am trying to change the property of background color on mouseover
of the nav ul li
element but when I select another element of the same kind I want the first one to revert its color and the newly selected to change color and so on. 我正在尝试在
nav ul li
元素的mouseover
时更改背景颜色的属性,但是当我选择相同类型的另一个元素时,我希望第一个元素恢复其颜色,并且希望新选择的元素更改颜色,依此类推。
$(document).ready(function() {
$('nav ul li').on('mouseover', function() {
if ($(this).css('background-color') == '#BBB') {
$(this).css("background-color", "#36D900");
} else {
$(this).css("background-color", "#BBB");
}
});
});
Try the code 尝试代码
$('nav ul li').hover(function(){
$('nav ul li').css("background-color", "#BBB");
$(this).css("background-color", "#36D900");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.