Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a small script that customises certain list views, hiding buttons.

This is done using jQuery $(document).ready()

Because this js is manipulating standard pages it is stored in the left sidebar.

However, I can see that the call to the function is being made when the document is not really ready. I'm guessing that salesforce is fetching list contents (including buttons) dynamically.

So my attempts to show or hide something are in vain because that thing has not yet been inserted into the page.

How can I make sure that this script get executed when salesforce is done rendering the list completely?

share|improve this question
What list are your referring to exactly? Can you provide more specific details and maybe some sample code? – fehays Aug 6 '14 at 15:19
It's the standard list view page (aka one of the search layouts) for a custom object. – powlo Aug 7 '14 at 16:04
up vote 4 down vote accepted

Presumably you are aware that Salesforce is making this sort of code harder to add - see End of javascript sidebar hacks?.

If you can detect (e.g. by the presence of an element of a certain class) when the rendering is done, then you can poll for that using JavaScript's setTimeout:

function checkIfThere() {
    // Check for the element and do whatever you need to if you find it
    var foundIt = ...;
    if (!foundIt) {
        // Do the check again in 500 ms
        setTimeout(checkIfThere, 500);
    } else {
        // All done
// Call directly to start it
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.