How to remove class from all elements jquery

后端 未结 6 1244
野性不改
野性不改 2021-01-31 23:58

I am changing the class of an element with the following

  $(\"#\"+data.id).addClass(\"highlight\")

Given the list below.

 <         


        
相关标签:
6条回答
  • 2021-02-01 00:38

    You need to select the li tags contained within the .edgetoedge class. .edgetoedge only matches the one ul tag:

    $(".edgetoedge li").removeClass("highlight");
    
    0 讨论(0)
  • 2021-02-01 00:43

    The best to remove a class in jquery from all the elements is to target via element tag. e.g.,

    $("div").removeClass("highlight");
    
    0 讨论(0)
  • 2021-02-01 00:44

    This just removes the highlight class from everything that has the edgetoedge class:

    $(".edgetoedge").removeClass("highlight");
    

    I think you want this:

    $(".edgetoedge .highlight").removeClass("highlight");
    

    The .edgetoedge .highlight selector will choose everything that is a child of something with the edgetoedge class and has the highlight class.

    0 讨论(0)
  • 2021-02-01 00:51
    $(".edgetoedge>li").removeClass("highlight");
    
    0 讨论(0)
  • 2021-02-01 00:53

    You could try this:

     $(".edgetoedge").children().removeClass("highlight");
    
    0 讨论(0)
  • 2021-02-01 00:58

    try: $(".highlight").removeClass("highlight");. By selecting $(".edgetoedge") you are only running functions at that level.

    0 讨论(0)
提交回复
热议问题