Being a beginner in web design, I have a question. From what I understand, styles can be coded using CSS or JS (on the HTML side). Ultimately, all of these "actions" are stored in the DOM.
If I have an HTML document with CSS styles associated with it, can I override the CSS through JS (written directly on the HTML side) by manipulating the DOM?
Update:
@treddie You must ensure that any JavaScript referencing elements in the DOM is executed after those DOM elements have been loaded into memory. This is why we typically recommend placing your <script> element just before the closing body tag (</body>). – Scott Marcus
It seems like I attempted to do just that, by placing the following Javascript at the end of the HTML body, but nothing happened.
<script>
x1t=x1r.toString(); /* x1r was calculated earlier in this script */
var Product_Linky = document.getElementById("Product_Link_Container");
Product_Linky.style.left=x1t;
</script>
</body>
However, my lack of experience in HTML, CSS, and JS doesn't surprise me.
This question already has an answer here:
Changing element style attribute dynamically using JavaScript 10 answers
Apologies for not being able to find existing questions when I don't know the exact phrases to search for. Nevertheless, thank you for the 3 upvotes! (I always do Abs(votes)).