PDA

View Full Version : embedde space in id


ez4ne12c
11-17-2002, 01:41 AM
Hi I am trying to use outerHTML to make an image visible

i pass the variable parameter "name"
to the function

...
appear just toggles the visiblity, and it works if the id is a single word but if the id has a space in it i have a problem

appear="<span id='christianname surname'style='position: relative;left: -150px; display: inline; visibility: visible;'>"
appear+="<img src='frame.gif'></img>";
appear+="</span>";

alert(appear);

name.outerHTML=appear;
alert(name+" added")

the part where i get stuck is that there is a space in the span id
i have tried
name.value.outerHTML=appear;

does anyone know how to assign the outerHTML property to a span id with an embedded space

Thanks
ez

beetle
11-17-2002, 09:57 PM
Your ids shouldn't have spaces. Use underscores or capitalization...

id="christian_name_surname"

or

id="christianNameSurname"

glenngv
11-18-2002, 07:26 AM
ids with spaces are just fine. just don't use the dot syntax. Use this instead:

document.getElementById("christianname surname")

beetle
11-18-2002, 07:32 AM
Originally posted by glenngv
ids with spaces are just fine.Yes, but it's not a good programming practice...IMHO

glenngv
11-18-2002, 07:45 AM
yeah I agree. :D
just pointed out that it's possible to use ids with spaces.

Ankun
11-18-2002, 08:29 AM
er I dont think its good practice to use IDs that are that long anyway..it just makes the file size larger than it needs to be, just use something that is long enough for you to understand what it means.

ez4ne12c
11-18-2002, 11:30 PM
Thanks 4 solutions and comments.
The id format is 'beyond my control' it is generated from users file of names, therefore i have not much choice.

It is also used for generating graphical labels and text in a presentation credit roll-over. The BIG BOSS does not like his name scrolled on a projector as BIG_BOSS hehehe..

Ideally i do try to use a single word or underscores when using id..

thanks :thumbsup:
ez

beetle
11-18-2002, 11:40 PM
No hurdle that can't be jumped....

var theName = "The_Big_Boss";
alert(theName.replace(/_/g," ");

:D

ez4ne12c
11-18-2002, 11:48 PM
Beetle..that works.. even though im alergic to :eek: regular expressions!:eek: Unfortunately i wasnt allowed to change the ids .. "those who know best" want the spaces IN the ids..
hmmmmmmm
Tks
ez

beetle
11-19-2002, 12:02 AM
NP, I understand. We can't be in control of everything....:D