highlight html list option when clicking

0

How can I do so that when I click on an option in an html list the backgroud of a color that stands out over the other options remains, I have done it with the active property but it does not do what I need and with the property hover then it works but only passing the mouse over it but when I click it the backgroud disappears

.enlace > a:hover {
 cursor:pointer;
  background: yellow;
}
<html>
<head>

</head>
<body>
<ul>
  <li class="enlace"><a href="#">Liga 1</a></li>
  <li class="enlace"><a href="#">Liga 2</a></li>
  <li class="enlace"><a href="#">Liga 3</a></li>
  <li class="enlace"><a href="#">Liga 4</a></li>
</ul>
</body>
</html>
    
asked by Ivxn 20.11.2017 в 04:25
source

2 answers

0

Instead of using a:hover use a:focus because hover acts when the mouse pointer passes over it.

On the other hand, focus acts by selecting the element with the mouse pointer or by using the tabulator, but in turn loses permanence by clicking anywhere on the page. Greetings

    
answered by 20.11.2017 / 04:46
source
1

If you want to use Jquery, you could do the following,

$("#lista").click(function()
            {
                $("selected#lista").addClass("background:orange");
            })
    
answered by 20.11.2017 в 20:06