Copy all styles from one element to another

后端 未结 3 1848
臣服心动
臣服心动 2020-12-14 05:49

How can i get every styles (even inherited) from an element A to an element B ? in javascript or using jquery.

let\'s tell i have an element

3条回答
  •  孤城傲影
    2020-12-14 06:17

    Try to copy every CSS-properties like this:

    $("#target").css("border", $("#source").css("border"));
    $("#target").css("background", $("#source").css("background"));
    #source {
      background-color: #dfeacb !important;
      color: #bbae4e !important;
      border: 1px solid green !important;
    }
    
    
    

    Why not? you can create the dictionary that may consists of all properties.

提交回复
热议问题