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

前端 未结 9 1978
不知归路
不知归路 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条回答
  •  -上瘾入骨i
    2020-12-01 08:44

    Generally you can access style parameter using .attr('style'). If you want to access computed style you can use window.getComputedStyle(element) in Opera, Firefox, Chrome and other sane browsers. For IE you'd do the same with element.currentStyle.

    Also if you wish to access individual CSS style you can do so with jQuery .css method. Like so $("#divId").css('font-size').

提交回复
热议问题