![]() |
Finding and replacing a line
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 |
Re: Finding and replacing a line
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[i].cssRules respectively document.styleSheets[i].rules You can search those rules for the selector and then access the individual property declarations. -- Martin Honnen http://JavaScript.FAQTs.com/ |
Re: Finding and replacing a line
On Sun, 04 Jun 2006 22:33:02 +1000, Andrew Poulos
<ap_prog@hotmail.com> 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> |
| All times are GMT. The time now is 12:02 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.