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

Execute javascript within {!Component } lookup

I'm trying to dynamically access a set of VisualForce elements:

function addClassToFields(string, class){
    ids = string.split(',');
    for(var x=0;x<ids.length;x++){
        obj = document.getElementById(ids[x]);
        if (obj) {
            classname = obj.className;
            obj.className =  classname + ' ' + class;


This function receives a set of IDs, comma separated, and tries to add an additional style class to them.  I know the recommended method for looking up the actual IDs is something like

obj = document.getElementById({!$Component.lookingForThisId});

is there any way to drop back into Javascript within {! }, so I can append the ID I want to $Component....?  Something like

var myid = 'fieldName';
obj = document.getElementById({!Component.jsExec('myid')});