Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #19384
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Based on its src value, find an image and assign an ID? |
| Date | 2013-04-20 23:42 +0200 |
| Organization | albasani.net |
| Message-ID | <kkv24n$b15$1@news.albasani.net> (permalink) |
| References | <kkv0sq$8mp$1@news.albasani.net> |
On 2013-04-20 23:21, Tuxedo wrote:
> Using a same header image, e.g. <img src=placeholder.gif> that is generated
> and cannot be changed after it's been initially loaded into a page view,
> can an ID be assigned later in the document flow?
The easiest way is to use querySelector() or querySelectorAll():
var ele = document.querySelector("[src='placeholder.gif']");
If support for older browsers is a concern, there are some libraries
that can simulate the querySelector* methods (usually returning a static
array instead of a live collection).
jQuery has something like that built-in (called Sizzle, I believe), as
do most other general purpose libraries, and there is one popular
library only for this purpose, but its name escapes me at the moment.
Other than that, you could try XPath (where supported), or just iterate
over document.images and compare the src-attributes until you find your
image.
If you don't actually need the element (for example, if you only want to
hide it), you can also do that with CSS:
img[src='placeholder.gif'] { display: none }
- stefan
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Based on its src value, find an image and assign an ID? Tuxedo <tuxedo@mailinator.com> - 2013-04-20 23:21 +0200
Re: Based on its src value, find an image and assign an ID? Stefan Weiss <krewecherl@gmail.com> - 2013-04-20 23:42 +0200
Re: Based on its src value, find an image and assign an ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-21 00:22 +0200
Re: Based on its src value, find an image and assign an ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-21 00:36 +0200
Re: Based on its src value, find an image and assign an ID? Stefan Weiss <krewecherl@gmail.com> - 2013-04-21 00:52 +0200
Re: Based on its src value, find an image and assign an ID? Scott Sauyet <scott.sauyet@gmail.com> - 2013-04-20 17:20 -0700
Re: Based on its src value, find an image and assign an ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-21 11:09 +0200
Re: Based on its src value, find an image and assign an ID? Scott Sauyet <scott.sauyet@gmail.com> - 2013-04-23 06:32 -0700
Re: Based on its src value, find an image and assign an ID? x@x.com (znôrt) - 2013-04-21 00:56 +0200
Re: Based on its src value, find an image and assign an ID? x@x.com (znôrt) - 2013-04-21 00:59 +0200
csiph-web