如何使用jQuery删除和添加新的css类?
这是我的例子如何使用jQuery删除和添加新的css类?,jquery,Jquery,这是我的例子 <a href="javascript:void(0)" id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_A" title="10" style="text-decoration:none"><span id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_Star_1" class="ratingS
<a href="javascript:void(0)" id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_A" title="10" style="text-decoration:none"><span id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_Star_1" class="ratingStar emptyRatingStar" style="float:left;"> </span><span id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_Star_2" class="ratingStar filledRatingStar" style="float:left;"> </span><span id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_Star_3" class="ratingStar filledRatingStar" style="float:left;"> </span><span id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_Star_4" class="ratingStar filledRatingStar" style="float:left;"> </span><span id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_Star_5" class="ratingStar filledRatingStar" style="float:left;"> </span>
</a>
因此,我需要在单击时从锚定选项卡的所有子元素中删除ratingStar filledRatingStar类,并应用不同的类ratingStar emptyRatingStar尝试:
$("a").click(function() {
$(this).children().removeClass("filledRatingStar").addClass("emptyRatingStar");
});
尝试:
您可以使用
.addClass()
和.removeClass()
:
希望这有帮助。干杯您可以使用
.addClass()
和.removeClass()
:
希望这有帮助。干杯
$("a").click(function(){
$(this).children().removeClass("filledRatingStar").addClass("emptyRatingStar");
});
$(document).ready(function(){
$("#ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_A").click(function(){
$(this).find("span").removeClass("filledRatingStar").addClass("emptyRatingStar");
});
});