2

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

gdoron
  • 147,333
  • 58
  • 291
  • 367
S Singh
  • 1,403
  • 9
  • 31
  • 47

1 Answers1

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

Working DEMO

gdoron
  • 147,333
  • 58
  • 291
  • 367
  • 1
    Doesn't quite work as requested... the styles aren't split when there are multiple by `;` and you missed the style from the containing #concernedHtmlPortion element. Seems you too, are capable of misreading the question! =) – ahren Mar 13 '12 at 09:25
  • Thanks! this is what i wanted. Although I have done using childnode concept but your provided code is better than mine. – S Singh Mar 13 '12 at 09:59
  • yeah. i accepted the answer. thanks to tell me! next time i will remember that. – S Singh Mar 15 '12 at 12:55
  • @user966709. You can still accept answers for your old questions. There is no time limitation. Good luck! – gdoron Mar 15 '12 at 13:20