[HTML/JavaScript] Creating a div by runtime

For everything that's not in any way related to PureBasic. General chat etc...
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

[HTML/JavaScript] Creating a div by runtime

Post by es_91 »

THIS POST HAS BEEN SOLVED. PLEASE SEE SECOND POST FOR THE ACTUAL PROBLEM!

Propabbly, there are a lot of java gurus around here, so i'll try this here:

Code: Select all

<!DOCTYPE html>
<html><head><script type="text/javascript">function killElement(element) {If (element) {var papa = element.parentNode;If (papa) papa.removeChild(element);}}</script>
</head>
<body>
<font face="Courier"><div id="background" style="width:720px;">
</div></font>
<script type="text/javascript">
document.getElementById("background").innerHTML = "Guten Tag.<br />"
</script>
<script type="text/javascript">
killElement(document.getElementById("background"));
</script>
</body>
</html>
Why is not the <div> part of the web site deleted?

/EDIT: Solved. Thanks to RSBasic!

Code: Select all

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
             onload = function() {
                var papa = document.getElementById("background");
                if (papa) {
                    papa.innerHTML = "Guten Tag.<br />"
                    papa.parentNode.removeChild(papa);
                }
            }
         </script>
    </head>
    <body>
        <font face="Courier">
            <div id="background" style="width:720px;"></div>
        </font>
    </body>
</html>
Last edited by es_91 on Fri Apr 04, 2014 5:01 am, edited 1 time in total.
:mrgreen:
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Re: [HTML/JavaScript] Pleeease delete this <div>! [SOLVED]

Post by es_91 »

another question ... why can't i create a new <div> element as a child to a span element?

Code: Select all

<!DOCTYPE html>
<html>
<head>
	<script type="text/javascript">
		onload = function() {
			var neuerBackground = document.createElement("div");
			neuerBackground.style.color = "#FF0000";
			document.getElementById("main").appendChild(neuerBackground);
		}
	</script>

</head>
<body>
	<span id="main"></span>
</body>
</html>

:mrgreen:
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: [HTML/JavaScript] Creating a div by runtime

Post by helpy »

Check the html specification and the differences between flow content and phrasing content.
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Re: [HTML/JavaScript] Creating a div by runtime

Post by es_91 »

Thanks. :)
:mrgreen:
Post Reply