Browsed through the CSS impact panels

.Tab1 {
  background-image: url("http://dl.dg-site.com/wp-content/themes/aeron/images/dl-products-icons5.jpg");
  background-repeat: no-repeat;
  background-position: center;
  background-clip: content-box;
  width: 100px;
  height: 75px;
  display: block;
  padding: 20px;
}
.Tab1:hover {
  border: 2px solid #8CC63F;
}
.Tab1:visited {
  border: 2px solid #8CC63F;
}
.Tab2 {
  background-image: url("http://dl.dg-site.com/wp-content/themes/aeron/images/dl-products-icons3.jpg");
  background-repeat: no-repeat;
  background-position: center;
  background-clip: content-box;
  width: 100px;
  height: 75px;
  display: block;
  padding: 20px;
}
.Tab2:hover {
  border: 2px solid #8CC63F;
}
<ul>
  <li class="Tab1"></li>
  <li class="Tab2"></li>
</ul>

I have created a list with tabs, but I'm having trouble getting the selected item to display a border of 2px solid #8CC63F.

I've tried some solutions in the code section, but it doesn't seem to be working as expected. Can anyone help me figure out what's wrong?

Your assistance is greatly appreciated!

Answer №1

It appears that the issue lies in using the :visited selector, which is typically used for anchor tags (<a>).

To apply this functionality to list elements, you can simply add a class on click.

var listArray = document.querySelectorAll("[class^=Tab]");

function setVisited() {
  this.classList.add("visited")
}

for ( var list = 0; list < listArray.length;  list++) {
  listArray[list].addEventListener("click", setVisited , false)
}
ul li{border:2px solid transparent; margin-bottom: 10px}
ul li:hover,ul li.visited{border:2px solid #8CC63F;}
<ul>
  <li class="Tab1">Tab1</li>
  <li class="Tab2">Tab2</li>
</ul>

You can achieve the same effect with jQuery as well:

$("[class^=Tab]").click(function(){$(this).addClass("visited")})
ul li{border:2px solid transparent; margin-bottom: 10px}
ul li:hover{border:2px solid #8CC63F;}
ul li.visited{border:2px solid #8CC63F;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<ul>
  <li class="Tab1">Tab1</li>
  <li class="Tab2">Tab2</li>
</ul>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The button refuses to navigate to a URL upon being clicked

Struggling with my JavaScript buttons. Currently, they are functioning flawlessly, but I am attempting to change my "Order Online" button into a link that opens a new window to a Menufy menu page. Unfortunately, I can't seem to crack the code on how t ...

Is there a way to create a gradual fading effect on my images?

Check out the images currently on my portfolio page: .collection-type-gallery #slideshow .slide img:hover { opacity: 1; -webkit-transition: opacity 1s ease-in-out; -moz-transition: opacity 1s ease-in-out; -o-transition: opacity 1s ease ...

Design a square confined within an adjustable rectangular container

Looking to fill a rectangular area on my page with a square positioned in the center, regardless of whether the rectangle is horizontal or vertical. Many existing solutions focus solely on creating a square from the width of a containing box, which doesn&a ...

Is enclosing a div around HTML5 semantic elements a good practice?

Have you ever wondered about the best way to use a div with HTML5 semantic markup? I've been pondering this question for some time and haven't found a definitive answer online. One way you could do it is like this: <div class="header-wrapper ...

Deliver static assets integrated within Express using HTML template

I have a directory of text files that I'm currently serving through Express using express.static. Here's the code snippet: const express = require('express') const app = express() const port = 3000 var serveIndex = require('serve- ...

Incorporate a section of text to flow around a floated image within a paragraph

https://i.sstatic.net/s5aFq.png How can I achieve the text wrapping above an image similar to the layout in the sunflower picture? I have tried using relative positioning and adjusting the top property, but it doesn't allow the text to wrap around th ...

Clickable element with embedded URL and functionality

Currently, I have an href attached to a block of text that triggers an action (specifically, swapping out the current div for another). However, I'd like to change this text into a button. The problem is that I can't nest a button tag inside an a ...

The recommended style guide for HTML documentation advises using spaces within the <code> tags

While reviewing the style guide for maintaining extensive documentation of an existing system using HTML for a client, I came across a particular rule that text within a code tag should be surrounded by spaces, like so: ..., the element<code> STATE ...

Organize Divs - Arrange each div below its corresponding image using JavaScript and jQuery

Here is a sample structure I am working with: <div class="main"> <div class="image">Image1</div> <div class="image">Image2</div> <div class="image">Image3</div> & ...

Ways to display or conceal form controls when altering select box choices

In my HTML, I have two select boxes: the first for Country and the second for City. The requirement is to display a textbox when a user selects a country other than Pakistan and show a dropdown list for city if the user selects Pakistan from the country dr ...

Is it possible to swap the src of the Next.Js Image Component dynamically and incorporate animations in the

Is there a way to change the src of an image in Nextjs by using state and add animations like fadein and fadeout? I currently have it set up to change the image source when hovering over it. const [logoSrc, setLogoSrc] = useState("/logo.png"); <Image ...

What is the recommended way to adjust the width of a paper-textarea element in Polymer 1.0?

Is there a way to adjust the width of a paper-textarea? I have tried using CSS selectors within Polymer 1.0 style tags, but it does not seem to be effective. The paper-textarea element is made up of paper-input-container. I attempted the following approach ...

css how to style a table row with a specific identifier

Although this question has been asked millions of times on the internet, my English skills are not great and I struggle to find the right words to search. I have a table with a specific ID set up like this: <table class="tableClass"> <tr id="one ...

Eliminate HTML field based on checkbox status

I'm looking to dynamically remove HTML fields based on a Yes/No condition. I've shared the code below for better understanding. If Yes is selected, I want to hide the No Field/Input/Box and vice versa. function AutoCheck() { if (document.getEl ...

Designing a solid sidebar of a specific width alongside a flexible container for content that adapts to different screen sizes using

I have a sidebar that is fixed at 200px on the left side of the page, and a responsive content container on the right side. To center the content in the right container, I used the following CSS: .sidebar { width: 10%; position: fixed; height: 100%; bac ...

Animating text-shadow color in CSS from left to right

I need help with transitioning the text-shadow color horizontally on hover. I found a solution that demonstrates how to do this here: Although it shouldn't matter, I am working in react with styled-components. Here is an example of what I am trying ...

Tips for validating multiple forms on a single page without altering the JavaScript validation structure

My JSP page currently consists of two forms: <body> <form id="1"></form> <form id="2"></form> </body> Only one form is visible at a time when the page is viewed. A JavaScript validation file is used to check the ...

Is it necessary for CSS Media query to load all the referenced CSS files?

When utilizing a CSS Media Query to assign two different stylesheets, such as desktop.css and mobile.css based on the max-width, how does this process function? Is it necessary for both stylesheets to be loaded by the browser every time, and then the appr ...

Turn the process of transforming a .createElement("image") into a clickable link

I have successfully organized the images the way I wanted, but now I would like each image to be a clickable link that leads to its own URL Current Image Code: <img src="01.jpg" /> Desired Image Link Code: <a href="01.jpg" target="_new">< ...

Is it possible for me to connect one element to another using CSS or JavaScript?

On my website, there are three columns of interactive elements that can be scrolled vertically. Users are able to select one item from each column, and once selected, the chosen elements are connected by lines. The challenge I am facing is determining ho ...