Jump to content

“How to Include HTML” code on w3school does not work...


Recommended Posts

I tried including the 'tab.html' and ‘content.html’ into my 'index.html' (using w3school code: how to include HTML, found at: https://www.w3schools.com/howto/howto_html_include.asp), but the javascript and css elements do not work. The buttons don't work as intended. Look at:

If you minimize the browser window, the tab is supposed to change to a drop-down menu, but the button does not work at all. I have checked the individual pages and they seem to work just fine, just not when they are combined. 

Am I doing something wrong? Could someone help? All the code I used is from w3school and I have only modified the file names (tab.html and content .html to point to the right files). Below are links to the code:


Code for ‘tab.html’ - https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_topnav


Code for ‘content.html’ - https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_collapsible_symbol


Code for ‘index.html’ - https://www.w3schools.com/howto/tryit.asp?filename=tryhow_html_include_2

Edited by Centaurette
Link to comment
Share on other sites

Nevertheless the way I explained to you on how it should be done, is the correct method, just because it didn't work, doesn't mean it is wrong.

When the page is fully loaded and you view the source you should see singular <!doctype html>, <html><head>...</head><body>...</body></html> tags with content, usually duplicate of these are highlighted in red meaning it is a error.

There maybe a issue with including html and the applying of events, before the html actually exists, especially for collapsible JavaScript code. you could try using setTimeout() to wait a second before applying the events.

Link to comment
Share on other sites

  • 1 year later...

Try checking consolelog, I checked and it turns out that the protocol being used by my computer or browser to access the HTML files is being blocked, since I had no problem with this when I pushed to GitHub, I assume it's a local problem.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...