我有一个 div 可以更改 id。我已经检查了新的 id 在那里。然后我打电话给新的身份证做别的事情,什么也没发生。
我怎样才能让 div 只有在它具有特定的 css 时才做某事?在示例中,如何仅在 div 为灰色时将其淡出?
$("#red").click(function() {
$('#red').attr('id', 'grey');
});
$("#grey").click(function() {
$('#grey').attr('id', 'red');
$('#grey').fadeOut(800);
});
#red{
position: absolute;
top:10px; left:10px;
width:100px; height:100px;
background-color:red;
cursor:pointer;
}
#grey{
position: absolute;
top:10px; left:150px;
width:100px; height:100px;
background-color:grey;
cursor:pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="red"></div>