JQuery - remove cssObject after adding?
I do this:
var cssObject = {
'background-color' : '#042c59',
'-moz-box-shadow' : '0 0 22px #111',
'-webkit-box-shadow' : '0 0 22px #111',
'box-shadow' : '0 0 22px #111'
}
$('#mydiv').css(cssObject);
开发者_JAVA技巧}
I can't seem to figure out how to remove that same cssObject from mydiv.
you are not adding a css object, you are adding a map that jquery interprets and sets the css values on the objects selected. If you want to toggle css style easily, I recommend addClass, removeClass, or toggleClass.
.selected{
background-color : #042c59,
-moz-box-shadow : 0 0 22px #111,
-webkit-box-shadow : 0 0 22px #111,
box-shadow : '0 0 22px #111
}
$('#mydiv').toggleClass("selected");
精彩评论