JQuery css function not working in all browsers

Given this HTML, CSS and JavaScript: http://jsfiddle.net/XvqYS/3/

If you run it in Google Chrome, it alerts

10px

Running it on IE, Safari or FireFox alerts and an empty line. Why?

I am using IE9, Chrome 18.0.1025.168, FireFox 12.0, Safari 5.0.4

+3
source share
1 answer

You must use separate properties, such as margin-left.

The main method for reading all properties: http://jsfiddle.net/XvqYS/8/

$(function () {
    var $main = $("#main");
    var margin = [
        $main.css('margin-top'),
        $main.css('margin-right'),
        $main.css('margin-bottom'),
        $main.css('margin-left')
    ].join(' ');
    alert(margin);
});

You can configure it to return a compact value , for example. 10px 10px 10px 10px→ 10px.

+6
source

All Articles