See STYLES in javascript - paying $50

Discussion in 'JavaScript' started by ruby, Jun 13, 2008.

  1. #1
    Hi everyone, I'm having an issue that's doing my head in and I kind of need some quick assistance. Anyone that can help me solve this I will pay $50 into your PAYPAL account!

    Basically I have this:

    <STYLE>
    .at_ { width:325px; background-color: none; padding: 3px; }
    .at2 { padding-bottom: 1px; padding-top: 4px; padding-left: 3px; padding-right: 3px; vertical-align:top; text-align:left; }
    </STYLE>

    I have some javascript just under it where I need to basically get those styles, put them into a variable.

    <SCRIPT>
    var styles ="";
    </SCRIPT>

    I have done a fair bit of looking around but can't seem to find a method that will allow me to do this, but it must be possible!

    Any help appreciated... there's $50 in it for the person that either gives me a solution or at least assists finding one!
     
    ruby, Jun 13, 2008 IP
  2. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Please PM with with your exact requirements. I can extract the styles from the <style> and </style> but do you need just all the styles in a single string or you want some breakup too?
     
    rohan_shenoy, Jun 13, 2008 IP
  3. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #3
    rohan_shenoy, Jun 14, 2008 IP
  4. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #4
    I just require all the styles in a single string... the styles could be different to and there could be more
     
    ruby, Jun 14, 2008 IP
  5. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #5
    ruby, Jun 14, 2008 IP
  6. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Ruby, I have sent you a PM.
     
    rohan_shenoy, Jun 14, 2008 IP
  7. gorantla

    gorantla Peon

    Messages:
    115
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    is still u want this?
    i will do 4 u if u want now?
    abhi
     
    gorantla, Jun 14, 2008 IP
  8. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Here is something to get you started:

    function dumpStyleSheet(n){
    	var ie = !!window.ActiveXObject, styles = "";
    	if (!ie){
    		var i = 0, rules = document.styleSheets[n].cssRules, l = rules.length;
    		for ( ; i < l; i++)
    			styles += rules[i].cssText;
    	}
    	else
    		styles = document.styleSheets[n].cssText;
    	return styles;
    }
    PHP:
    This will dump all the contents of the chosen style sheet - n - and return them for you.

    The first argument is which stylesheet to dump as a page can have an unlimited number of stylesheets. Counting starts at 0. So to get the text in the first stylesheet you would say dumpStyleSheet(0), to get it from the second you would say dumpStyleSheet(1), and so on.

    So to do what you want in your first post just do this:

    var styles = dumpStyleSheet(0);
    PHP:
    The function should work in any modern browser.
     
    MMJ, Jun 14, 2008 IP