How to change the color of the text after clicking on it in Squarespace?
Where in the code do I insert the block id to target a particular block?
Here is the code I was trying to use
<script>
document.getElementById('change').onclick = changeColor;
function changeColor() {
document.body.style.color = "purple";
return false;
}
</script>
I need some help with JavaScript
3
Answers
You need to apply the CSS on the DOM element you want to style not on the
document.body
.Just as a side note, nowadays it’s preferred to use an eventlistener for things like this since it doesn’t completely override a property of an element. (
onclick
in this case)you can change "foo" to anything you want but it needs to be unique.
Put the ID of the CSS selector you’re targeting as an attribute in the HTML element.
Within the java script it would be like this