0

I keep getting undefined with this script...

I

document.getElementById(new_id).style.top = Top; //Works Fine
document.getElementById(new_id).style.left = Left; //Works Fine
document.getElementById(new_id).style.backgroundColor = Background_Color; //Works Fine
document.getElementById(new_id).style.border = Border_Width+" "+Border_Type+" "+Border_Color; //Works Fine
        
new_code = document.getElementById(new_id); //Doesn't Work!!!!
        
document.write(new_code.value);

I style the element correctly, but when I want to write it I keep getting "undefined"?

5
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by ko ko
0

When you do alert(document.getElementById(new_id) just before line 1 and before line 5, what are the 2 values that come up?

0

It depends on the type of element. Are you sure your element has a .value property?

.value on a div will give undefined, where .value on a textbox will give you the value.

0

I have a div not a textbox and I still am using .value. Plus when I alert it without .value I get [object HTML DivElement] both times.

What do I need to do to fix it? So I can't use .value? What do I use to echo the entire div including <div style="...">...Content...</div> all of that?

0

So basically all I want to do is get all of that div...

<div style="...">...Content...</div>

And place it inside a variable...

0

Try using innerHTML, and remove .value property on "new_code":

var new_code = document.getElementById(new_id)[B].innerHTML[/B];
document.write(new_code);
0

I fixed it I added a new div around it and then called innerHTML thanks everyone!

<div id="div1">
     <div id="div2"></div>
</div>

//Javascript

var new_code = document.getElementById("div1").innerHTML;

After doing that I get all of div2!

0

Please mark this thread as Solved if your problem was solved. It will make use clear that there is no need to answer in this thread.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.