Each component in a Visualforce page has its own Id attribute. When the page is rendered, this attribute is used to generate the Document Object Model (DOM) ID. Use $Component.Path.to.Id in JavaScript to reference a specific component on a page, where Path.to.Id is a component hierarchy specifier for the component being referenced.
function beforeTextSave() { document.getElementById('{!$Component.msgpost}').value = myEditor.getEditorHTML(); }
<apex:page> <apex:outputText id="msgpost" value="Emacs"/> is great. </apex:page>
<apex:page> <apex:pageBlock id="theBlock"> <apex:pageBlockSection id="theSection" columns="1"> <apex:pageBlockSectionItem id="theSectionItem"> <apex:outputText id="theText"> Heya! </apex:outputText> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:page>
document.getElementById(
"{!$Component.theBlock.theSection.theSectionItem.theText}")