...

View Full Version : Resolved Multi document.getElementById string?



DJCMBear
12-23-2010, 03:41 AM
Hey very quick question how could I do this?

Basicly I have this html code.


<div id="editor">
<div id="tools"></div>
</div>


Now my javascript mods the editor by using the 'editor' id how can I use the variable for the 'editor' to look inside itself for the id 'tools', a bit like this and I know this doesn't work as I tried it but how could I do this.



var editor = document.getElementById('editor'),
tools = editor.getElementById('tools');
// Basicly it will have the editor as the root so
// if tools is also somewhere else on the page it
// wont pick it up, id's will never be 2 the same
// but just in-case there is lol.

jmrker
12-23-2010, 05:54 AM
I'm a bit unclear about what it is that you want to do, :confused:
but for a possible guess, try this (see comments in red)

Hey very quick question how could I do this?

Basicly I have this html code.


<div id="editor">
<div id="tools">Contents of Tools</div>
</div>


Now my javascript mods the editor by using the 'editor' id how can I use the variable for the 'editor' to look inside itself for the id 'tools', a bit like this and I know this doesn't work as I tried it but how could I do this.



var editor = document.getElementById('editor'),
tools = editor.getElementById('tools');
// Basicly it will have the editor as the root so
// if tools is also somewhere else on the page it
// wont pick it up, id's will never be 2 the same
// but just in-case there is lol.
alert(tools.id);
alert(tools.innerHTML);

DJCMBear
12-23-2010, 06:26 AM
I managed to get around it by writing this var tools = document.getElementById('editor').getElementsByTagName('*'); and then checking the id with a for loop, as I read that you can't do the way I wanted to do.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum