<分区>
Possible Duplicate:
Facing weird problem while adding and removing class.
假设我有以下 html--
<div class="div_portlet ui-widget ui-widget-content ui-corner-all defaultcontentbg portlet-width default_border default_border_color portlet_space">
<div class="div_header headertitle align_center defaultheadercolor portlet-header-left-padding default_bottom_border default_border_color">
<span class="ui-icon ui-icon-minusthick"></span>
Order Header Level Information</div>
<div id="ordrHdrLvnInfn" class="div_content portlet-width">
我想做的是,检查 span with class ui-icon ui-icon-minusthick
是否存在,如果存在先删除它然后添加它。我尝试了以下方式,但它不起作用
javascript 函数::
jQuery.fn.initPortlet = function( parent_component ,header , component ){
this.find(header).find('span.ui-icon').remove();
this.addClass("ui-widget ui-widget-content ui-corner-all")
.find(header)
.addClass("headertitle")
.addClass("align_center")
.addClass("defaultheadercolor")
.end()
.prepend('<span class="ui-icon ui-icon-minusthick"></span>')
.find(component);
}
我以这种方式调用这个函数..
$('.div_portlet').initPortlet('.div_portlet','.div_header','.div_content')
它应该先删除跨度然后添加它,但如果我多次调用此函数,那么它只会继续添加该跨度。
我该怎么做,或者有更好的方法来做到这一点。
谢谢!!!!!!