This time I will bring you js traversal and operation of css. What are the precautions for js traversal and operation of css? The following is a practical case, let’s take a look.
The specific code is as follows:
//js遍历添加栏目类添加css 再点击其它删除css $(".radio-group .ckselect").each(function(index) { $(this).click(function() { var tagid=$(this).attr('tagid'); $("#tagid").val(tagid) $(".ckselect").removeClass("selected"); $(".ckselect").eq(index).addClass("selected") }) });
//js点击显示关闭层,空白区域也关闭 $(".zu-top-nav-userinfo").click(function(e) { if ($(".peoples").hasClass("allhide")) { $(".peoples").hide(); $(".peoples").removeClass("allhide"); return } e.stopPropagation(); $(".peoples").show(); $(".peoples").addClass("allhide") }); $(document).click(function() { if ($(".peoples").hasClass("allhide")) { $(".peoples").hide(); $(".peoples").removeClass("allhide") } });
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Detailed explanation of Vue two-way data binding examples
Detailed explanation of the steps for using function throttling and time-sharing functions
The above is the detailed content of js traversal operation css. For more information, please follow other related articles on the PHP Chinese website!