Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28908

Re: Change all background-color attribute values

From Janis Papanagnou <janis_papanagnou@hotmail.com>
Newsgroups comp.lang.javascript
Subject Re: Change all background-color attribute values
Date 2015-11-22 16:49 +0100
Organization Aioe.org NNTP Server
Message-ID <n2so5q$b40$1@speranza.aioe.org> (permalink)
References <n2sj7k$ttl$1@speranza.aioe.org> <1s2gno1nefvn1$.1wp02kmbye2jj$.dlg@40tude.net>

Show all headers | View raw


On 22.11.2015 16:32, JJ wrote:
> On Sun, 22 Nov 2015 15:24:53 +0100, 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?
>>
>> Thanks for any hints.
>>
>> Janis
> 
> IMO, there's no simple solution. It depends on how the web page was created.
> How the background color was previously applied.

I have control over the webpage creation, and I can make changes if that helps
to achieve what I want. Currently I have HTML definitions like

  <style type="text/css">
  .U { background-color: #fafafa }
  .V { background-color: #f7f7f7 }
  ...
  </style>
  ...
    <td class="U" ...>
    <td class="V" ...>

Those <style> definitions are the only 'background-color' items in the whole
HTML code, so a brute force method (while ugly) could be applied as well (in
case that's possible).

> 
> If the background color was applied using the BGCOLOR HTML attribute, or if
> there is no background color applied to any of the elements, you can apply a
> CSS backgrould-color rule for all elements. The CSS will override the
> BGCOLOR attribute. e.g.
> 
>   * { background-color : orange }
> 
> By adding a new STYLE element containing the above CSS. e.g.
> 
>   var ele = document.createElement("STYLE");
>   ele.innerHTML = "* { background-color : orange }";
>   document.body.appendChild(ele);

I'm puzzled about this suggestion (one that the other poster also suggested),
because I don't want to create anything new but just change existing values.

> [HTML/CSS precedence information snipped]

Thanks for your reply.

Janis

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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