Is there anyway to target all of <th> in a table and declare same attribute for all of them?

i have this table with crazy amount of data,i was wondering isn’t there any way to access all <th> elements and set an attribute which will be apllied to all of them? for instance-

   <th colspan="7"> title </th>

i just wanna declare them in the beginning so that i don’t have to set each one of them, when i have a massive amount of data! :S

I think it might be possible to target the element by using the querySelector() method from the document object.

   const ths = document.querySelectorAll("th");
   ths.forEach(th => th.setAttritube("colspan", "7");

Let me know if it works. :slight_smile:

1 Like

Hey,yes.this is how it is done with JS.I was wondering if there any built-in HTML way of doing luck.haha. Thanks man!

1 Like