I am having a issue where I am able to supposed to change my css file using javascript to edit the "href" attribute. The problem that I am having is that I cannot differentiate when a button is pressed or not. I have 2 buttons one for StyleA and one for StyleB. I am not allowed to edit the html file at all, I am wondering what did I do wrong. Java Script
"use strict";
window.onload = function() {
let elements = document.getElementsByTagName('button');
document.getElementById('styleA').addEventListener('click', () => {
document.getElementById('styleSheet').setAttribute('href', 'styleA.css');
});
document.getElementById('styleB').addEventListener('click', () => {
document.getElementById('styleSheet').setAttribute('href', 'styleB.css');
});
};
Html
<link id="styleSheet" href="styleA.css" rel="stylesheet" type="text/css">
<!-- ... -->
<form>
<button id="styleA" type="submit">Use styleA</button>
<button id="styleB" type="submit">Use styleB</button>
</form>
My approach is to use the "addEventListener" to know when a button is pressed and accurately change the css file.