0

Hello i have a question. First of all my English is not that good so please dont blame me and im just starting in coding so my skills are low too. So.. i have my website and i remember there was a way to set a class too all elements What i exactly need.. I need a code that will set class=Auth to all clickable elements on my page I hope you understood what i mean, again sorry for my English and my low skill, i will appreciate any help, thank you! Ive tried searching help on other sites but it didnt help, hopefully someone will help me there.

1 Answers1

0

First css based solution:

<style>
  /*try listing all clickable html elements, separated by a comma*/
  a, button, etc {style:value;} 
</style>

Second css based solution:

<style>
  /*selects all (*) elements that are considered active (clicked on)*/
  *:active {style:value;}
</style>

That being said, if you need the class="AUTH" attribute to be included in every clickable element, I would highly recommend just adding it into the html code. This will save render time for the browser since it won't have to change it every time the pages loads. If that isn't an option, you could manually do it with javascript:

<script>
  //function runs when the document is loaded. all a elements and button elements and etc elements are selected, and have the AUTH class added to them.
  document.addEventListener("DOMContentLoaded", function() {
    document.querySelectorAll("a,button,etc").classList.add("AUTH");
  });
</script>
Scott Shaffer
  • 29
  • 1
  • 7
  • So, if i get it right, i just need to add in my html file before

    and thats it?

    – Alex Moma May 29 '21 at 21:33
  • If I understand what you are attempting to do, then you want to add that within the html header. You would also want to modify what selectors are being selected... so, a is clickable, button is clickable. You'll want to add any other clickable elements that you want to that list. Each separated by a comma. – Scott Shaffer May 29 '21 at 21:45