function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sathishsfdcsathishsfdc 

apex command button onclick keep the button highlighted even after panel refresh

is there any possible way to keep the command button highlighted even after panel refresh
<apex:page controller="HideAndShow">
<script type="text/javascript">
    var buttonClicked = null;
    function highlight(id) {
    if(buttonClicked != null )
    {
        buttonClicked.style.background = "#cccccc";
        buttonClicked.style.color =  "black";
    }

    buttonClicked  = document.getElementById(id);
    buttonClicked.style.background =  ""#87ceeb";
    buttonClicked.style.color =  "white";
    
    } </script>

<apex:form id="fm1"  >
                   <apex:commandButton id="btn1" action="{!firstButton}" value="{click1)"   onclick="highlight(this.id)"   /> 
            <apex:commandButton id="btn2" action="{!secondButton}" value="{click2)" onclick="highlight(this.id)"   /> 


               <apex:outputPanel id="one" rendered="{!firstPanel}" >
               panel1
               </apex:outputpanel>
               
                          <apex:outputPanel id="on1e" rendered="{!secondPanel}" >

panel2                                         </apex:outputpanel>

    </apex:form>
  </apex:page>


global with sharing class HideAndShow{
   
   public boolean firstPanel{get;set;}
   public boolean secondPanel{get;set;}

   
    public HideAndShow() {
     
     firstPanel = false;
     secondPanel = false;

    }

    public void firstButton()
    {
      firstPanel=false;
      secondPanel= false;

    
    }
   public void secondButton()
    {
      firstPanel=false;
      secondPanel= true;

    
    }

The onclick keeps the button highlighted for a second and then returns to the original colour.I want to keep the colour highlighted
even afer panel refresh
sandeep madhavsandeep madhav
Hi,

Hope this helps,

Use oncomplete and call the function which highlet the button.

"The JavaScript invoked when the result of an AJAX update request completes on the client."

Mark this as best answer if it helps.