addClass not working?
addClass not working?
为什么addClass不能工作?当点击step
类的div时,div的背景和字体颜色应该改变,但是什么都没有发生。
<html>
<head><style type="text/css">
.currentstep {
background-color:#eeb345; padding:5px; color:#000000; font-size:14px; font-family:Arial;
}
#stepcontainer {
overflow:hidden; width:100%;
}
.step {
float:right; width:auto; margin-right:2px; background-color:#59758d; padding:5px; color:#FFFFFF; font-size:14px; font-family:Arial; cursor:pointer;
}
</style>
<script type="text/javascript">
$(function(){
$('.step').live('click',function() {
$(this).addClass('currentstep');
$(this).siblings('.step').removeClass('currentstep');
});
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div id='stepcontainer'><div id='reset'><a>Reset</a></div>
<div class='step'>Step 3</div><div class='step'>Step 2</div><div class='step'>Step 1</div></div>
</body></html>
您将.step
和.currentstep
应用于相同的div(我假设您不想从div中删除.step
)。来自.step
的background-color
是第一个,所以这是固定的颜色。
尝试更改.currentstep
的CSS定义为:
.currentstep
{
background-color:#eeb345 !important;
padding:5px;
color:#000000;
font-size:14px;
font-family:Arial;
}
这里工作正常:http://jsfiddle.net/tomtheman5/j6f6w/
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Rxjs5, distinct() is not working
- createOscillator noteOn not working
- Javascript - .getHours() not working
- Javascript setTimeout not working | onkeydown
- MongoDB $pull not working
- Express router.use not working
- JSONP not working
- window.opener not working in chrome & IE
- Backbone + RequireJS: Collection.each() is not working