Finding and replacing a line

Discussion in 'Javascript' started by Andrew Poulos, Jun 4, 2006.

  1. Say I have some CSS, which is several hundred lines long, with the
    contents in this format:

    ..foo {
    blah
    color:#000;
    blah
    }
    ..bar {
    blah
    color:#FFF;
    }

    where the selectors and their opening braces, their closing braces, and
    declarations are each on their own lines (always), how can I replace a
    specific declaration (line) given a unique selector and a declaration
    property. For example, if I wanted the 'color' declaration property line
    in the 'bar' class changed.

    At the moment I'm iterating through the CSS one line at a time looking
    for the selector and then looking for the declaration property (before I
    hit the closing brace).

    Andrew Poulos
     
    Andrew Poulos, Jun 4, 2006
    #1
    1. Advertising

  2. Andrew Poulos wrote:

    > Say I have some CSS, which is several hundred lines long, with the
    > contents in this format:
    >
    > .foo {
    > blah
    > color:#000;
    > blah
    > }
    > .bar {
    > blah
    > color:#FFF;
    > }
    >
    > where the selectors and their opening braces, their closing braces, and
    > declarations are each on their own lines (always), how can I replace a
    > specific declaration (line) given a unique selector and a declaration
    > property. For example, if I wanted the 'color' declaration property line
    > in the 'bar' class changed.


    If you have that CSS in a HTML style element or in an external
    stylesheet linked in with the HTML link element then browsers like
    Mozilla or Netscape or IE build a DOM with
    document.styleSheets
    and
    document.styleSheets.cssRules
    respectively
    document.styleSheets.rules
    You can search those rules for the selector and then access the
    individual property declarations.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 4, 2006
    #2
    1. Advertising

  3. Andrew Poulos

    JimK Guest

    On Sun, 04 Jun 2006 22:33:02 +1000, Andrew Poulos
    <> wrote:

    >Say I have some CSS, which is several hundred lines long, with the
    >contents in this format:
    >
    >.foo {
    > blah
    > color:#000;
    > blah
    >}
    >.bar {
    > blah
    > color:#FFF;
    >}
    >
    >where the selectors and their opening braces, their closing braces, and
    >declarations are each on their own lines (always), how can I replace a
    >specific declaration (line) given a unique selector and a declaration
    >property. For example, if I wanted the 'color' declaration property line
    >in the 'bar' class changed.
    >
    >At the moment I'm iterating through the CSS one line at a time looking
    >for the selector and then looking for the declaration property (before I
    >hit the closing brace).
    >
    >Andrew Poulos




    if (document.form_1.check_1.checked==true)
    {
    foo.style.backgroundColor="ff8780";
    }
    else (foo.style.backgroundColor="FFD700")






    <form name="form_1">
    <input type="checkbox" name="check_1">Checkbox 1
    </form>
     
    JimK, Jun 4, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Holness
    Replies:
    0
    Views:
    5,465
    Ben Holness
    Jan 6, 2006
  2. yaipa
    Replies:
    13
    Views:
    739
    yaipa
    Jan 19, 2005
  3. DarthBob88

    Finding and Replacing Substrings In A String

    DarthBob88, Sep 23, 2007, in forum: C Programming
    Replies:
    7
    Views:
    579
    Keith Thompson
    Sep 23, 2007
  4. Rob Meade

    Replacing - and not Replacing...

    Rob Meade, Apr 5, 2005, in forum: ASP General
    Replies:
    5
    Views:
    299
    Chris Hohmann
    Apr 11, 2005
  5. Andrew Poulos

    Finding and replacing text on a page

    Andrew Poulos, Apr 15, 2005, in forum: Javascript
    Replies:
    1
    Views:
    103
    Martin Honnen
    Apr 15, 2005
Loading...

Share This Page