this script works in jQuery 1.9, but does not work in 1.8. How to convert this script to jQuery 1.8 ?

NOT Working Demo on jsfiddle

Working Demo on jsfiddle

HTML

<div id="container">
    <div id="c1" class="aaa" style="text-align:right; color:red top:100px; ">child 1</div>
    <div id="c2" class="aaa" style="text-align:left; top:200px; ">child 2</div>
</div>

jQuery script

$("#container").children().each( function () {
    alert("element ID = " + $(this).attr('id'));
    var styleProps = $(this).css(["width", 
                                  "height", 
                                  "color", 
                                  "background-color", 
                                  "text-align", 
                                  "left", 
                                  "top", 
                                  "right", 
                                  "bottom"]);
    $.each(styleProps, function (prop, value) {
        alert(prop + " = " + value);
    });
});
有帮助吗?

解决方案

The css function accepting an array wasn't implemented until 1.9.

You'll probably have to do it by hand if you're using 1.8 (loop through the values one at a time).

var styleNames = ["width", "height", "color", ...etc... ];

var i;
var $elem = jQuery(this);
for (i = 0; i < styleNames.length; ++i) {
    alert(styleNames[i] + " = " + $elem.css(styleNames[i]));
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top