1

How can i do? I hope the block(li) will change color after selection

"onclick" should keep the color changing. But onclick has not changed. (Only use "onclick", not use "a herf")

css

<style>
    #table thead tr {
        background-color: #E95420;
        color: #fff;
    }
.nav-tabs > li > a{
  color:#888888 !important;
  border: medium none;
}
.nav-tabs > li > a:hover{
    background-color: #c3c3c3 !important;
    border: medium none;
    border-radius: 0;
    color:#fff;
}
.nav-tabs > li > a:active{
    background-color: #c3c3c3 !important;
    border: medium none;
    border-radius: 0;
    color:#fff;
}
.nav-tabs>li.active>a, .nav-tabs>li.active>a:hover, .nav-tabs>li.active>a:focus {
  color: #fff !important;
  background-color: #E95420 !important;
  border: 1px solid #888888 !important;
}

</style>

View

<div id="EditArea" class="panel-body with-nav-tabs panel-warning">
            <ul class="nav nav-tabs">
                <li role="tab" class="" onclick=1();> <a>1</a></li>
                <li role="tab" class="" onclick=2();> <a>2</a></li>
                <li role="tab" class="" onclick=3();> <a>3</a></li>
                <li role="tab" class="" onclick=4();> <a>4</a></li>
                <li role="tab" class="" onclick=5();> <a>5</a></li>
                <li role="tab" class="" onclick=6();> <a>6</a></li>
            </ul>
</div>

script (function 1~6, Just to adjust the display of other parts)

 function 1() {
         $('#XXXXX').removeClass('hidden d-none');  
         $('#OOOOO').addClass('hidden d-none');
        }

Thank you

2
  • post your javascript / jquery function. Commented Feb 26, 2020 at 6:43
  • javascript , just to adjust the display of other parts Commented Feb 26, 2020 at 6:49

3 Answers 3

4

Below is the simple and a short code to change or set the color of item in menu onclick or active menu.

$(document).on('click', '.nav-tabs li', function() {
  $('.nav-tabs li').removeClass('active');
  $(this).addClass('active');
});
.nav-tabs li {
  color: #000000;
}

.nav-tabs li.active {
  color: #ff9933;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="nav nav-tabs">
  <li role="tab" class="active"> <a>1</a></li>
  <li role="tab"> <a>2</a></li>
  <li role="tab"> <a>3</a></li>
</ul>

Sign up to request clarification or add additional context in comments.

Comments

3

You can try this may i will help you Add this function as JS

function changeColors(element)  
{  
links=document.getElementsByTagName("li") ;  
for (var i = 0 ; i < links.length ; i ++)  
links.item(i).style.color = 'black' ;  
element.style.color='orange' ;  
}

HTML part will be like this.

<ul>  
<li onclick="changeColors(this);">li 1</li>  
<li onclick="changeColors(this);">li 2</li>  
<li onclick="changeColors(this);">li 3</li>  
</ul>

Comments

3

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<style>
  #table thead tr {
    background-color: #E95420;
    color: #fff;
  }
.nav-tabs > li > a{
  color:#888888 !important;
  border: medium none;
}
.nav-tabs > li > a:hover{
    background-color: #c3c3c3 !important;
    border: medium none;
    border-radius: 0;
    color:#fff;
}
.nav-tabs > li > a:active{
    background-color: #c3c3c3 !important;
    border: medium none;
    border-radius: 0;
    color:#fff;
}
.nav-tabs>li.active>a, .nav-tabs>li.active>a:hover, .nav-tabs>li.active>a:focus {
  color: #fff !important;
  background-color: #E95420 !important;
  border: 1px solid #888888 !important;
}

</style>
</head>
<body>

<div id="EditArea" class="panel-body with-nav-tabs panel-warning">
            <ul class="nav nav-tabs">
                <li role="tab" class=""> <a>1</a></li>
                <li role="tab" class=""> <a>2</a></li>
                <li role="tab" class=""> <a>3</a></li>
                <li role="tab" class=""> <a>4</a></li>
                <li role="tab" class=""> <a>5</a></li>
                <li role="tab" class=""> <a>6</a></li>
            </ul>
</div>
<script>
$(function(){
  var li = $('li[role="tab"]');
  li.on('click',function(){
  	li.removeClass('active')
    $(this).addClass('active');
  });
});
</script>
</body>
</html>

4 Comments

"onclick" needs to be used individually
What you mean by individually? You mean different colors for different items?
This means i need to use.... function1(){............},function2(){.........},function3(){......}
Thanks for answering, I used the following way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.