Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28906
| From | Janis Papanagnou <janis_papanagnou@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Change all background-color attribute values |
| Date | 2015-11-22 16:38 +0100 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <n2sni1$9l0$1@speranza.aioe.org> (permalink) |
| References | <n2sj7k$ttl$1@speranza.aioe.org> <n2smdk$fkj$1@news.albasani.net> |
On 22.11.2015 16:19, Martin Honnen wrote:
> Janis Papanagnou wrote:
>> I want to iterate over the DOM to change all background-color attribute
>> values, (informally written) something like
>>
>> for (obj in DOM)
>> if (obj.hasAttribute(background-color))
>> obj.background-color = some_funct(obj.background-color)
>>
>> Is there a way to achieve that in such a simple form? Or maybe even simpler,
>> without addressing the objects but just change all existing background-color
>> attributes?
>
>
> I don't think in HTML 4 or HTML5 any element has an attribute named
> "background-color", in HTML 4 some elements like the `body` element and the
> `td` elements have a deprecated `bgColor` attribute,
> http://www.w3.org/TR/html4/present/graphics.html#adef-bgcolor.
>
> In general you would use CSS and the "background-color" property, usually with
> CSS rules for certain elements or element belonging to a certain class. You
> could then manipulate the CSS rules or add new ones. Brute force would
> probably adding a rule
>
> var style = document.createElement('style');
> style.textContent = '* { background-color: darkblue !important }';
> document.documentElement.children[0].appendChild(style);
Thanks for your response. To clarify my intention; I have a HTML definition
<style type="text/css">
.U { background-color: #fafafa }
.V { background-color: #f7f7f7 }
...
</style>
...
<td class="U" ...>
<td class="V" ...>
and want to add GUI controls and javascript code to dynamically change the
predefined definition of all 'background-color' values, depending on its
respective previous value.
>
> Of course you seem to want to read out the existing background-color, as there
> is no such attribute that is not going to work the way you have shown it, and
> with CSS you would need to decide which value you want to read out, one set
> directly as an inline style (element.style.backgroundColor), one set in a
> certain rule, the computed one.
I was aware that the code I posted will not work; as I said it was informal,
with the purpose to describe what I would like to achieve. Since I'm not that
familiar with javascript pointers to concrete constructs would help me a lot.
I hope the additional information clarifies the issue and my intention.
Janis
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Change all background-color attribute values Janis Papanagnou <janis_papanagnou@hotmail.com> - 2015-11-22 15:24 +0100
Re: Change all background-color attribute values Martin Honnen <mahotrash@yahoo.de> - 2015-11-22 16:19 +0100
Re: Change all background-color attribute values Janis Papanagnou <janis_papanagnou@hotmail.com> - 2015-11-22 16:38 +0100
Re: Change all background-color attribute values Martin Honnen <mahotrash@yahoo.de> - 2015-11-22 17:02 +0100
Re: Change all background-color attribute values Janis Papanagnou <janis_papanagnou@hotmail.com> - 2015-11-22 18:18 +0100
Re: Change all background-color attribute values Martin Honnen <mahotrash@yahoo.de> - 2015-11-22 19:27 +0100
Re: Change all background-color attribute values Scott Sauyet <scott.sauyet@gmail.com> - 2015-11-22 11:33 -0800
Re: Change all background-color attribute values Janis Papanagnou <janis_papanagnou@hotmail.com> - 2015-11-23 16:01 +0100
Re: Change all background-color attribute values JJ <jj4public@vfemail.net> - 2015-11-22 22:32 +0700
Re: Change all background-color attribute values JJ <jj4public@vfemail.net> - 2015-11-22 22:47 +0700
Re: Change all background-color attribute values Janis Papanagnou <janis_papanagnou@hotmail.com> - 2015-11-22 16:54 +0100
Re: Change all background-color attribute values Janis Papanagnou <janis_papanagnou@hotmail.com> - 2015-11-22 16:49 +0100
Re: Change all background-color attribute values Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-11-23 01:11 +0000
Re: Change all background-color attribute values Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-11-23 11:27 +0000
csiph-web