drayarms Posted April 8, 2012 Share Posted April 8, 2012 Hello, I am trying to use the iterator from a for loop as a variable that would dictate various css attributes on a page. So here is the loop. It is actually part of a larger program which I won't and has been greatly edited because what the program tries to accomplish is irrelevant to my question. It works except that I'm not sure how to set that iterator as attribute values. for(i = 0; i < frame_count; i++){ $(".frame").slice(i,i+1).show(); //Display right odd frames $(".frame").slice(i,i+1).css({"top":"-798px","left":"102px","z-index":"-1", "height":"380px", "width":"180px"}); //Position right odd frames }//End of for loop Now for this line, .slice(i,i+1).css({"top":"-798px","left":"102px","z-index":"-1", "height":"380px", "width":"180px"}); Im actually trying to replace the numeric values with multiples of i such as "top": "-798*i" or in some cases, a complex algebraic expression involving i such as "left":"(102*i + 3)px" How do I accomplish that? Any ideas please? Quote Link to comment https://forums.phpfreaks.com/topic/260532-how-can-one-set-a-jq-variable-as-an-attribute/ Share on other sites More sharing options...
trq Posted April 8, 2012 Share Posted April 8, 2012 $(".frame").slice(i,i+1).css({"top": (-798 * i) + "px","left": (102 * i + 3) + "px","z-index":"-1", "height":"380px", "width":"180px"}); Quote Link to comment https://forums.phpfreaks.com/topic/260532-how-can-one-set-a-jq-variable-as-an-attribute/#findComment-1335296 Share on other sites More sharing options...
drayarms Posted April 8, 2012 Author Share Posted April 8, 2012 @ thorpe, thanks. just what i needed. Quote Link to comment https://forums.phpfreaks.com/topic/260532-how-can-one-set-a-jq-variable-as-an-attribute/#findComment-1335401 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.