![]() |
VOOZH | about |
To change the color of a link on click and keep it that way using JavaScript, you can modify its style or apply a CSS class. Here's how you can achieve this:
Output:
<a> tag with an id and class. The class="link" is used to group multiple links if needed..active-link sets the desired color for the clicked link. You can customize the color as per your requirement.active-link class is added to it.event.preventDefault() prevents the default link behavior (navigation) if necessary.active-link class from all links and then add it to the clicked link.If you have multiple links and want to keep track of which one was last clicked, you can use a similar approach by applying the event listener to all links with a common class:
Output:
active-link class is used to change and persist the color.addEventListener() method handles clicks on links.