Search code examples
javascriptjquerycsshtml-parsinghtml-content-extraction

Extract all inline css of concernet html


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 !!


Solution

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

    Working DEMO