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

后端 未结 9 1076
长情又很酷
长情又很酷 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:33

    $.fn.cssCopy=function(element,styles){
    var self=$(this);
    if(element instanceof $){
        if(styles instanceof Array){
            $.each(styles,function(val){
                self.css(val,element.css(val));
            });
        }else if(typeof styles===”string”){
            self.css(styles,element.css(styles));
        }
    }
    return this;
    };
    

    Use example

    $("#element").cssCopy($("#element2"),['width','height','border'])
    

提交回复
热议问题