Take the 2-minute tour ×

I want to change the DOM of a visualforce page. So how can I get the pageblock element with Javascript?


<apex:pageblock title="Filter" id="block">



Thank you

share|improve this question
add comment

2 Answers

Here's a jquery example of how you'd access it:


That would return a jquery object which you could further use with jquery, or call


to get the underlying DOM element.

If you're using plain Javascript, you'll have to look at the generated HTML to find out what the full ID is. The use the DOM to get the element:

document.getElementById("j54:j01:block"); // the Id is made up, but it will be at least as ugly as this

jQuery's $= operation alleviates the need for this. The direct DOM solution is not as reliable because the generated ID will change if you change where the pageBlock lives. In other words, any change in the pageBlock's ancestors will cause the Id to change.

share|improve this answer
add comment

The supported way to reference components in JavaScript is to use $Component, for example use {!$Component.idName} to obtain the DOM ID of the HTML element generated by <apex:outputPanel id="idName">.


share|improve this answer
add comment

Your Answer


