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
Justin MitchellJustin Mitchell 

How can I toggle visibility of an element on a Visualforce page using a button?

I know there must be 10 different ways to do this but I am reaching my knowledge limit here and need some help.

I have a table on my visualforce page which is pulling a list of all Workstep__c records that are related to a defined Sub_Order__c object.
Here's a much simplified version of my list:
<apex:pageBlock >
        <apex:pageBlockSection columns="1">            
            <apex:pageBlockTable value="{!wsList}" var="ws">   
                                             
                <apex:column headerValue="Name" value="{!ws.Name}" />                   
                <apex:column headerValue="Duration" value="{!ws.Duration__c}" />
                 
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
I need to have a button or a link at the top of the page that, when pressed, toggles visibility for any Workstep__c records on the list that have a Duration__c value of 0.

Right now I have a bunch of style classes defined in CSS and I've applied conditional styling to each column in order to hide the rows with a duration of 0, and it works just fine (though it's messy.. still trying to figure out how to clean it up a bit), however I want to be able to toggle the visibility of those rows on or off with a button. Suggestions for what direction to look?
 
Best Answer chosen by Justin Mitchell
Dario BakDario Bak
Hi Justin, using pure Javascript you can do this:
 
document.getElementsByClassName('appBanner')[0].style.visibility='hidden';

There are other ways to get this done using jQuery, but I assume you don't know jQuery .... yet.

All Answers

Dario BakDario Bak
Hi Justin, using pure Javascript you can do this:
 
document.getElementsByClassName('appBanner')[0].style.visibility='hidden';

There are other ways to get this done using jQuery, but I assume you don't know jQuery .... yet.
This was selected as the best answer
Justin MitchellJustin Mitchell
Thank you! That was enough to get me on the right track. It's all working now. :)