Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #26046
| From | "Jukka K. Korpela" <jkorpela@cs.tut.fi> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Dynamically assign image map values? |
| Date | 2014-10-30 19:57 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <m2tu5b$lkq$1@dont-email.me> (permalink) |
| References | (1 earlier) <m2q89q$c5m$1@dont-email.me> <m2qkt1$reb$1@news.albasani.net> <m2rbk4$a71$1@news.albasani.net> <m2rjvi$r6c$1@news.albasani.net> <m2tssv$d2r$1@news.albasani.net> |
2014-10-30 19:35, Tuxedo wrote:
>> var area = document.createElement("area");
>> area.setAttribute("href","bla");
>> area.setAttribute("coords","100,100,300,300");
>> area.setAttribute("shape","rect");
>
> If the area coords attributes are variables, how can they be included in
> the area.setAttribute function? Eg.:
You need to construct an expression that yields a suitable string as its
value.
> 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);
So you don’t quote the variable names, as they need to be evaluated, not
used literally. And you quote the commas, as they are to be taken
literally. The plus + operator performs string catenation when its
operands (or at least one of the operands) is a string.
--
Yucca, http://www.cs.tut.fi/~jkorpela/
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