Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Finding and replacing a line

Reply
Thread Tools

Finding and replacing a line

 
 
Andrew Poulos
Guest
Posts: n/a
 
      06-04-2006
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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      06-04-2006


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/
 
Reply With Quote
 
 
 
 
JimK
Guest
Posts: n/a
 
      06-04-2006
On Sun, 04 Jun 2006 22:33:02 +1000, Andrew Poulos
<(E-Mail Removed)> 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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding and Replacing Substrings In A String DarthBob88 C Programming 7 09-23-2007 03:14 PM
Finding and replacing Invalid Tokens in an XML document Ben Holness Perl 0 01-06-2006 12:11 PM
Finding and replacing text on a page Andrew Poulos Javascript 1 04-15-2005 11:30 AM
Replacing - and not Replacing... Rob Meade ASP General 5 04-11-2005 06:49 PM
finding/replacing a long binary pattern in a .bin file yaipa Python 13 01-19-2005 09:20 PM



Advertisments