First of all, 'stringifying' javascript should be avoided wherever possible. It generally leads to more errors than hard code does. You cannot really do the first example without eval() which is hokey. You could do it without a string/quotes though:
Code:
var temp = document;
With style you can do it with [] notation:
Code:
var temp = 'style';
var tooltip = document.getElementById('tipdiv');
tooltip[temp].width = '50px';
//is the same as
tooltip.style.width = '50px';
There's little value in doing that though. But with individual properties of style it can be handy in situations where you don't know the style property you want to set ahead of time. A more common way to use style in a situation like that is:
Code:
var tooltip = document.getElementById('tipdiv');
var temp = tooltip.style;
temp.width = '50px';
//is the same as
tooltip.style.width = '50px';
as many style declarations for tooltip can be made with minimal typing.
Bookmarks