jQuery - How to get all styles/css (defined within internal/external document) with HTML of an element

前端 未结 9 1982
不知归路
不知归路 2020-12-01 08:22

I know that $(\"#divId\").html() will give me innerHtml. I also need its styles (which might be defined by the means of classes) either in-line style

9条回答
  •  时光取名叫无心
    2020-12-01 08:48

    You can get the stylesheet defined inside style tags under document.styleSheets. You can read the rules into a map, and find them by selectorText. So by id: "#id", by classes: ".className". By safari or chrome you can use getMatchedCSSRules.

提交回复
热议问题