this seems like its probably basic js 101, but being a noob I'm having a hard time figuring out the solution. the example the basic example i will use to represent my real issue would be simplified down to if i had page with two elements; a paragraph and a box. I want the box to change to the color red when the contents of the paragraph say 'red. my best solution is the code below which was unsuccessful. any input would be appreciated. Thanks!
<body>
<p id="color">white</p>
<div id="box"></div>
<script>
var boxColor = document.getElementById('color')
function changeColor(boxColor) {
if (boxColor = 'red') {
document.getElementById('box').style.backgroundColor = 'red';
}}
</script>
</body>
Aucun commentaire:
Enregistrer un commentaire