Axel Richter: src einer bestimmten Grafik ändern

Beitrag lesen

Hallo,

Wenn die Grafik ein name-Attribut hat, funktioniert auch document.images["bildname"] bzw. document.images.bildname bzw. document.bildname.
laut Validator unter XHTML 1.0 strict nicht zugelassen :-)
das hatte ich schon probiert, bekam aber gleich eins auf die Finger *g*

Du kannst aber trotzdem mit der document.images-Collection arbeiten. Gib dem IMG-Element eine ID und nutze

document.images.namedItem("BildID")

Das document.getElementById ist hierfür viel zu unperformant, da es ja die images-Collection ohnehin gibt.

http://www.w3.org/TR/1998/WD-DOM-19980720/level-one-html.html
...
interface HTMLDocument : Document {
           attribute  wstring              title;
  readonly attribute  wstring              referrer;
  readonly attribute  wstring              fileSize;
  readonly attribute  wstring              fileCreatedDate;
  readonly attribute  wstring              fileModifiedDate;
  readonly attribute  wstring              fileUpdatedDate;
  readonly attribute  wstring              domain;
  readonly attribute  wstring              URL;
           attribute  HTMLElement          body;
  readonly attribute  HTMLCollection       images;
  readonly attribute  HTMLCollection       applets;
  readonly attribute  HTMLCollection       links;
  readonly attribute  HTMLCollection       forms;
  readonly attribute  HTMLCollection       anchors;
           attribute  wstring              cookie;
  void                      open();
  void                      close();
  void                      write(in wstring text);
  void                      writeln(in wstring text);
  Element                   getElementById(in wstring elementId);
  NodeList                  getElementsByName(in wstring elementName);
};
...

interface HTMLCollection {
  readonly attribute  long                 length;
  Node                      item(in long index);
  Node                      namedItem(in wstring name);
};
...

namedItem
This method retrieves a Node using a name.

Parameters
name  The name of the Node to be fetched.

Return Values
The Node with a name or id attribute whose value corresponds to the specified string. Upon failure (e.g., no Node with this name exists), returns null.

This method raises no exceptions.

viele Grüße

Axel