Is there a way to target the ID of a div element within another html page using Javascript? Ive been using document.getElementByID which works fine when targeting Ids within the main index.html template.
When I create a separate html template and load in another Javascript file within the head of the page, the functions are no longer being triggered.
Well typically JavaScript is executed on the page it is loaded into. Remember that often a browser is going to read the HTML file from top to bottom. When it finds the <script> tag and then immediately load in and execute that JavaScript code (which is often why you see advice to load those scripts towards the end of the page). If the element with the ID you are trying to target is not yet read by the browser at the time it reads the JS (lets say your DIV is defined after your <script> tag) it may not yet see the element.
Now without having seen your HTML or your JavaScript and how you are bringing it in, it is hard to say what is going on. Can you show us the code of both your HTML and JS files so we can see why it might not be working?
@keyframes stateoverlayclose {
from { opacity: 1; left: 10;}
to {opacity: 0; left: -700px;}
}
Index.js code where the sidebar.html code is being loaded into another window. Thought I’d include this as well, although i don’t think this is the problem.
The alert function in the sidebar.js file is triggered no problem its only the moveIconsLeft() function which isn’t working which i don’t get either. The sidebar.css script is also being loaded into the html file with no issues, apart from the “stateoverlayclose” keyframe.
I’ve managed to fix it! i wasn’t specifying the type attribute in the script tag. Also i moved both script tags which contained the .js files in both html files towards the end of the body tag.