如何将类添加到已分配给它的类的现有li
?
我当前的代码已开启 http://jsfiddle.net/GbPdV/
我想将“Open”类添加到:
< li class="dropdown hover carticon cart" >
我认为这必须发生在:(不确定)
if ( response.Status == "Success" )
{
$.ajax({
type: "GET",
url: "dmiajax.aspx?request=FloatingCart&extra=" + rnd(),
dataType: "html",
success: function(response) {
var floatingCart = $("ul.dropdown-menu.topcart");
if (floatingCart.length == 0) {
floatingCart = $('<ul class="dropdown-menu topcartopen"></ul>').insertBefore(".pull-right");
floatingCart.hoverIntent({
over: function() {},
timeout: 200,
out: function() {
$(this).stop(true, true).filter(":visible").hide("drop", {
direction: "down"
});
}
});
}
答案 0 :(得分:6)
只需使用.addClass
floatingCart.addClass("Open");
success: function(response) {
var floatingCart = $("ul.dropdown-menu.topcart");
//HERE
floatingCart.addClass("Open");
if (floatingCart.length == 0) {
//OR HERE
floatingCart = $('<ul class="dropdown-menu topcartopen"></ul>')
.insertBefore(".pull-right")
.addClass("Open");;
floatingCart.hoverIntent({
over: function() {},
timeout: 200,
out: function() {
$(this).stop(true, true).filter(":visible").hide("drop", {
direction: "down"
});
}
}