Clone style in jQuery?

后端 未结 9 1585
轻奢々
轻奢々 2021-02-05 03:56

I have a called spn1, which has some style from inline + CSS file.

I have another called spn2

相关标签:
9条回答
  • 2021-02-05 04:39

    Try using this:

    document.getElementById("spn2").style = document.getElementById("spn1").style;
    
    0 讨论(0)
  • 2021-02-05 04:40

    If you just want the CSS, you can do the following:

    let cssText = document.defaultView.getComputedStyle( $("#elementID"), "").cssText;
    

    Then you can apply that to any new element.

    0 讨论(0)
  • 2021-02-05 04:41

    jQuery doesn't have any direct facilities for doing this. You will have to use plain old JavaScript to find a cross-browser way to copy over the computed style of one element to another. This answer has an implementation for a potential solution.

    0 讨论(0)
提交回复
热议问题