Question

I want to extract all inline styles of the concerned html.

For example, below is the concerned html for which inline css is to be extracted:

<div id="concernedHtmlPortion" style="style1">
    <div style="style2">
    <div style="style3;style4">Hello World!!</div>
    <div></div>
</div>

Is there any way to extract all style by using only root id="concernedHtmlPortion"?

Result of extraction should be: style1,style2,style3,style4

Any help please !!

Was it helpful?

Solution

var allStyles = [];
$('#concernedHtmlPortion, #concernedHtmlPortion [style]').each(function() {
    allStyles.push($(this).attr('style').split(';'));
});
alert(allStyles);​

Working DEMO

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top