extract CSS code from a HTML document

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dasrasmikant
    New Member
    • Jan 2008
    • 30

    extract CSS code from a HTML document

    Hello everybody,

    I want to print the all the code written between <style></style> element on click a button. Is it possible?? if yes can any body guide me regarding.

    thanks for your responses in advance.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    If it's just the CSS code between the style tags that you want and not other CSS, here's a quick way:
    [code=javascript]// assuming one style tag:
    document.getEle mentsByTagName( "style")[0].innerHTML[/code]

    Comment

    • dasrasmikant
      New Member
      • Jan 2008
      • 30

      #3
      Originally posted by acoder
      If it's just the CSS code between the style tags that you want and not other CSS, here's a quick way:
      [code=javascript]// assuming one style tag:
      document.getEle mentsByTagName( "style")[0].innerHTML[/code]
      Thnks Acoder. Its working fine. But what will be the line for extracting all the code between the body tag. IF I m writting like this
      [HTML]document.getEle mentsByTagName( "body")[0].innerHTML[/HTML].
      Its showing me the HTML Preview. But What to get its html code.

      Again Thanks very much Acoder for your right time help.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        That should give you the HTML code unless you're setting the innerHTML of another element with it. Set the value of a textarea instead.

        Comment

        Working...