The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › CSS › How to trigger click event
I have this code https://codepen.io/desandro/pen/htsui working as it is found at https://masonry.desandro.com/events.html
This page loads with all tiles purple. You will note everytime you click a purple tile it changes to yellow.
How could i create a link so when i enter it into a browser the appropriate tile is showing as coloured (yellow) on page load?
You could make use of ID’s on your elements, match these ID’s in your URL and read them in the onload function like this:
window.onload = () => { const item = document.querySelector(window.location.hash); if (item) { item.classList.add('grid-item--gigante'); } }; Optionally followed by msnry.layout();.
window.onload = () => { const item = document.querySelector(window.location.hash); if (item) { item.classList.add('grid-item--gigante'); } };
msnry.layout();