I am trying to loop .each() css value. I just know how to get the index. Fiddle
var pos = $('.sublayer_1 div').css('left');
function adjustAttempt3() {
$(".sublayer_1 div").each(function (index) {
alert(index + ":" + pos);
});
}
The idea I am going for is saving the left value, because when the browser is under 800px the jQuery code I wrote changes the left position, when the browser is resized back above 800px I want to resort back to the default left value.
FYI css is NOT a solution, because the left value is from the database and is dynamic.
This is why I am trying to store each left position and use that in an if statement.
Here is some sample html code, take a look at this fiddle for more.
<div class="sublayer_1">
<div style="position: absolute; left: 100px;">Coffee</div>
<div style="position: absolute; left: 300px;">More Coffee</div>
</div>
Side Note: More on what I mean by saving the orig left position
if((w) > 800) {
$Q('#main').css({'margin-top': mar });
$Q('.sublayer_1 div, .sublayer_1 img').css(pos);
alert(pos)
}
else {
$Q('.sublayer_1 div, .sublayer_1 img').css({'left': w/2});
$Q('#main').css({'margin-top': w_d + m_d });
}
This if statement is wrapped in a function which is called in a resize function. The variables in the if((w) > 800) statement are outside the function picking up the default values while the variables inside the else statement are within the resize function so that they are dynamic.
As far as practices go, IDK how this rates, but it just came to me and works, but I am having trouble getting each left value, which is why I ask what I did above.
.cssdocumentation: "Get the value of a style property for the first element in the set of matched elements"each()passes{left:'100px'}or something?this-- that's how you access the elements inside theeachloop,$(this)to access the jquery extended element.<div style="position: absolute; left: 100px;" data-original-left="100">Coffee</div>?