admin管理员组

文章数量:1418095

I am using jQuery with addClass to add class to some elements. But for some reason not all "td" get the class assigned (the ones with the .currentmonth).

$("td").addClass("aaawwwasdsad");

/

I am using jQuery with addClass to add class to some elements. But for some reason not all "td" get the class assigned (the ones with the .currentmonth).

$("td").addClass("aaawwwasdsad");

https://jsfiddle/wheelq/7Lesommm/

Share Improve this question asked Feb 14, 2016 at 20:23 meso_2600meso_2600 2,1366 gold badges26 silver badges50 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Because other Javascript functions run later.

Look : https://jsfiddle/p9kogsmL/14/

Define it into the end of calendar function :

     ...

        document.getElementById("calendar").innerHTML += calendarTable;
        $("td").addClass("aaawwwasdsad");
      }

If you want to add a class to all td ,you have to use each loop. here is an example:

$("td").each(function(){
   $(this).addClass("aaawwwasdsad");
});

本文标签: javascriptHow to add class to all TDStack Overflow