Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28915
| Path | csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Change all background-color attribute values |
| Date | Mon, 23 Nov 2015 01:11:49 +0000 |
| Organization | PointedEars Software (PES) |
| Lines | 44 |
| Message-ID | <2033421.7ht7S6j6Qy@PointedEars.de> (permalink) |
| References | <n2sj7k$ttl$1@speranza.aioe.org> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1448241110 24375 eJwFwYEBwDAEBMCVnnhiHKH2H6F3PC7eYU43Lhe60/TJzrel0nVdK+PUPEMIOGowYL5L0/4BJZUQ6w== (23 Nov 2015 01:11:50 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Mon, 23 Nov 2015 01:11:50 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwNyMEBwCAIA8CVoBCM41gD+4/Q3vMQ5XVXFioxGNlhN6lBXKJfo1x/DAybnc77uK3aUSdElz3yjNAOofMDWhoVFQ== |
| Cancel-Lock | sha1:O8/c17d47aNEQEHRrqlD5kjkgD8= |
| X-NNTP-Posting-Host | eJwNycEBwCAIA8CVRAw24wiY/Uew9z14WNRegVgQJF6eTbIOe5ZUUxrI9jK23b/GxvmcnCsTDzXmEYk= |
| Xref | csiph.com comp.lang.javascript:28915 |
Show key headers only | View raw
Janis Papanagnou wrote:
> I want to iterate over the DOM to change all background-color attribute
> values,
There is no ”background-color” attribute.
> (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?
Yes.
> Or maybe even simpler, without addressing the objects but just change all
> existing background-color attributes?
No. But you can change all declared ”background-color” values.
> Thanks for any hints.
[].slice.call(nodeList).forEach(function (node) {
var bgColor = document.defaultView.getComputedStyle(
node, null).getPropertyValue("background-color");
if (bgColor) node.style.backgroundColor = some_funct(bgColor);
});
or
[].slice.call(document.styleSheets).forEach(function (styleSheet) {
[].slice.call(styleSheet.cssRules || styleSheet.rules, function (rule) {
var bgColor = rule.style["background-color"];
if (bgColor) rule.style["background-color"] = some_funct(bgColor);
});
});
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
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