Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.
SignUp Now!
:active pseudo-class.:visited pseuo-class.so would it be something likeIf you mean while the mouse is being held down, then use the:activepseudo-class.
If you want to change the style of a link that has been clicked any time in the past, use the:visitedpseuo-class.
Otherwise, you'll have to use JavaScript with a click event listener.
document.getElementByClass("title_text3").addEventListener("click", underline);
document.getElementsByClassName().underline is an existing function that you've written, that's not going to work.const text = document.querySelector(".title_text3 a");
text.addEventListener("click", () => {
text.style.textDecoration = "underline";
});
Hi John,You probably meant to usedocument.getElementsByClassName().
Unlessunderlineis an existing function that you've written, that's not going to work.
Do something like this:
JavaScript:const text = document.querySelector(".title_text3 a"); text.addEventListener("click", () => { text.style.textDecoration = "underline"; });
querySelectorAll().const texts = document.querySelectorAll(".title_text3 a");
texts.forEach((text} => {
text.addEventListener("click", () => {
text.style.textDecoration = "underline";
});
});
I think I've figured out the problem. The text is part of my navigation bar div. It doesn't have a specific style associated with it. Problem is I don't know how to make it so that this text underlines when it's clicked as it's not even part of a div class.Are there more than one of the links that you want to change the colour when clicked?
If so, usequerySelectorAll().
JavaScript:const texts = document.querySelectorAll(".title_text3 a"); texts.forEach((text} => { text.addEventListener("click", () => { text.style.textDecoration = "underline"; }); });
I think I've figured out the problem. The text is part of my navigation bar div. It doesn't have a specific style associated with it. Problem is I don't know how to make it so that this text underlines when it's clicked as it's not even part of a div class.
!important applied may be overriding this style? Is the text targeted inside an <a> in your html (I hope so)?Code Forum is a community platform where coding enthusiasts can connect with other developers, engage in discussions, ask for help, and share their knowledge with a supportive community. It's a perfect place to improve your coding skills and to find a community of like-minded individuals who share your passion for coding.
We use essential cookies to make this site work, and optional cookies to enhance your experience.