Hi.. thank you for answering. I am sorry for make it confusing. I just need to know how to set css using variables that's created by array and for loop to simplify the script.
I am trying to create a simpler codes in js fiddle but it seem it will take too much time for me to make it work.
Here is if anyone want to fix it to help other:
http://jsfiddle.net/YJzLf/I had found the way to get what I want. The point is to access the css properties and values directly from the array, instead of convert it to a variable first:
Example:
- var style = {};
- var style[var1[a]] = var2[b];
If we are using if else statement, then just put the var style = {}; before the if. and var style[var1[a]] = var2[b]; inside it.
Example:
- for (var k=0; k<= anArray.length; k++) {
- var style = {};
- if (condition 1) {
- var style[var1[k]] = var2[k];
- } else if (condition 2) {
- var style[var1[k]] = var2[k] + 'px'; // may be we need to set the css value attribute like px, em, etc..
- }
- // and then we could simply use the variable style to set the css of an element
- $('.preview').css(style);
- }
CORRECTION : Take a look at the next reply!