Finding and replacing a line

A

Andrew Poulos

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
 
M

Martin Honnen

Andrew said:
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.
 
J

JimK

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top