Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #26048
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Dynamically assign image map values? |
| Date | 2014-10-30 19:46 +0100 |
| Organization | PointedEars Software (PES) |
| Message-ID | <28301755.4F9RsBvy3v@PointedEars.de> (permalink) |
| References | (2 earlier) <m2qkt1$reb$1@news.albasani.net> <m2rbk4$a71$1@news.albasani.net> <m2rjvi$r6c$1@news.albasani.net> <m2tssv$d2r$1@news.albasani.net> <m2tu5b$lkq$1@dont-email.me> |
Jukka K. Korpela wrote:
> 2014-10-30 19:35, Tuxedo wrote:
>> x1 = 100; y1 = 100; x2 = 300; y2 =300;
>>
>> area.setAttribute("coords","+x1+","+y1+","+x2+","+y2+");
>>
>> But this is wrong.
>
> Yes, because only the second argument matters here, the rest are
> discarded. You need this:
>
> area.setAttribute("coords", x1 + "," + y1 + "," + x2 + "," + y2);
This and all other setAttribute() calls should be replaced with the
corresponding form of
area.coords = x1 + "," + y1 + "," + x2 + "," + y2;
(Likewise, getAttribute() calls should be replaced by property-read access
unless the original markup attribute value is wanted.) [1]
Another possibility here is
area.coords = [x1, y1, x2, y2];
or (probably safer)
area.coords = [x1, y1, x2, y2].toString();
or
area.coords = [x1, y1, x2, y2].join();
or (explicit)
area.coords = [x1, y1, x2, y2].join(",");
The first form should work (untested in recent environments, but supported
by previous experience) because the type of the “coords” property should be
String, as it is an implementation of an interface attribute whose type is
DOMString; so a built-in setter of that property should convert the value
RHS to String. Then the following applies:
The string representation of an Array instance is the comma-separated list
of the string representation of its elements as returned by
Array.prototype.toString(). The string representation of String values is
their value; the string representation of Number values is the one that most
closely represents the nearest IEEE-754 “double precision” floating-point
value, in the simplest case the concatenated decimal digits.
As for the second one, the toString() method inherited by Array instances
returns the same as the inherited join() method when called without
argument. Array.prototype.join() without argument (with argument
“undefined”) defaults to a comma (“,”) as separator. [2] This is “probably
safer” than the former approach because it does not rely on a type-
converting setter LHS.
_________
[1] <http://www.w3.org/TR/2014/REC-html5-20141028/embedded-content-0.html#the-area-element>
(sic!)
[2] <http://ecma-international.org/ecma-262/5.1/#sec-15.4.4.2> pp.
--
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
Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-29 08:47 +0100
Re: Dynamically assign image map values? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-10-29 10:25 +0200
Re: Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-29 13:00 +0100
Re: Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-29 19:28 +0100
Re: Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-29 21:50 +0100
Re: Dynamically assign image map values? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-10-30 07:51 +0200
Re: Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-30 09:44 +0100
Re: Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-30 18:35 +0100
Re: Dynamically assign image map values? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-10-30 19:57 +0200
Re: Dynamically assign image map values? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-30 19:46 +0100
Re: Dynamically assign image map values? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-10-30 20:57 +0200
Re: Dynamically assign image map values? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-30 21:26 +0100
Re: Dynamically assign image map values? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-10-30 22:58 +0200
Re: Dynamically assign image map values? Tuxedo <tuxedo@mailinator.com> - 2014-10-30 20:52 +0100
Re: Dynamically assign image map values? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-10-30 22:23 +0200
csiph-web