jQuery CSS plugin that returns computed style of element to pseudo clone that element?

后端 未结 9 1185
长情又很酷
长情又很酷 2020-11-22 15:27

I\'m looking for a way using jQuery to return an object of computed styles for the 1st matched element. I could then pass this object to another call of jQuery\'s css method

9条回答
  •  鱼传尺愫
    2020-11-22 15:49

    I just wanted to add an extension to the code submitted by Dakota.

    If you want to clone an element with all of the styles applied to it and all the children elements then you can use the following code:

    /*
     * getStyleObject Plugin for jQuery JavaScript Library
     * From: http://upshots.org/?p=112
     *
     * Copyright: Unknown, see source link
     * Plugin version by Dakota Schneider (http://hackthetruth.org)
     */
    
    (function($){
        $.fn.getStyleObject = function(){
            var dom = this.get(0);
            var style;
            var returns = {};
            if(window.getComputedStyle){
                var camelize = function(a,b){
                    return b.toUpperCase();
                }
                style = window.getComputedStyle(dom, null);
                for(var i=0;i

    Then you can just do: $clone = $("#target").cloneWithCSS()

提交回复
热议问题