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

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 )
    { = "#cccccc"; =  "black";

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

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

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

panel2                                         </apex:outputpanel>


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

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


    public void firstButton()
      secondPanel= false;

   public void secondButton()
      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

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.