JavaScript – Simple Helper Functions

Get an HTML object element


function el(elementId){
    var elementObject = null;
    try{
        elementObject = document.all ? document.all[elementId] : document.getElementById(elementId);
    }catch(e){
        // nothing to do
    }
    return elementObject;
}

Trim a string

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

Set focus on an HTML object element

function focusElement(elementId){
    try{
        el(elementId).focus();
    }catch(e){}
}

Move an HTML object element

function move(elementId, x, y){
    try{
        var obj = el(elementId);
        obj.style.top= y;
        obj.style.left= x;
    }catch(e){
  	//alert("hoopz0");
    }
    return false;
}


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *