Skip to content
Advertisement

How to set a default active/open tab in html

I’m currently working on a Skill Test project that displays one question on each tab. How can I set the default active tab? I have code for default open tab which I just copied form w3schools.com, but it wont work. I don’t have an idea why. I hope someone can help me fix my code since Im new to these. Thank you so much!

Style:

JavaScript

Body:

JavaScript

Advertisement

Answer

I’ve just changed the color of hover to green and active to red. If you’re referring to make the first button active just modify to this:

JavaScript

We added “active” in the class. And modify your body tag to :

JavaScript

What are we doing?
We’re making the default button active initially and to make sure its content is also loaded, when body is loaded we’re invoking the onClick of the default button to show its content.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement