JavaScript function arguments statements -


my problem is: (only example, must not make sense overall):

// make function , pass part of statement argument function examplefunction( argument ) {     document.getelementbyid('testid')[0].style.argument = '#f00'; }  // later onload examplefunction( background ); 

i found out doesn't work way, can't find out how right. if correct example send me on way happy , thankful.

firstly document.getelementbyid returns single element (or null if no element found), not [0]. secondly if want reference property dynamically use [] notation

// make function , pass part of statement argument function examplefunction( argument ) {     document.getelementbyid('testid').style[argument] = '#f00'; }  // later onload examplefunction( 'background' ); 

http://jsfiddle.net/hm3mu/


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -