Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Finding and replacing a line (http://www.velocityreviews.com/forums/t925121-finding-and-replacing-a-line.html)

Andrew Poulos 06-04-2006 12:33 PM

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

Martin Honnen 06-04-2006 04:26 PM

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/

JimK 06-04-2006 08:58 PM

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:23 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.