473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

document.createelement('div') doesn't work?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>||Working with elements||</title>
  4. </head>
  5.  
  6. <script type="text/javascript">
  7. var my_div = null;
  8. var newDiv = null;
  9.  
  10. function addElement()
  11. {
  12.   // create a new div element
  13.   // and give it some content
  14.   newDiv = document.createElement("div");
  15.   newDiv.innerHTML = "<h1>Hi there and greetings!</h1>";
  16.  
  17.   // add the newly created element and it's content into the DOM
  18.   my_div = document.getElementById("org_div1");
  19.   document.body.insertBefore(newDiv, my_div);
  20. }
  21.  
  22. </script>
  23.  
  24. <body onload="addElement()">
  25. <div id='org_div1'> The text above has been created dynamically.</div>
  26. <script>
  27. var div = document.getElementsByTagName("div");
  28. document.write("<br>div= "+div.length);
  29. </script>
  30. </body>
  31. </html>
here div.length=1
Jul 29 '11 #1
1 2118
Rabbit
12,516 Expert Mod 8TB
It works fine. If you're opening it from your local machine, your browser might be blocking the script.
Jul 29 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
6
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: ...
3
by: Danny | last post by:
i am trying to load different pages and scanning some words out of the pages. But my problem is that the readystate is never 4 except when i show a msgbox example: ...
2
by: effendi | last post by:
Hi I tested the following function in Safari and it doesnt work. This is tested fine in IE. function processOutcome(){ mainDatabase=document.forms.AssessDatabase.value var...
0
by: Juna | last post by:
I have been working in vs2003, but now started to work in vs2005 but the problem, I have simple web application not website, which work i mean open in browser when we press F5 or run the...
3
by: jx2 | last post by:
hi guys i would appriciate your coments on this code - when i ran it for the very first time it doesnt see @last = LAST_INSERT_ID() but when i ran it next time it read it properly i need to know it...
1
by: Dany13 | last post by:
hi all. i using some text box for input value and some localvarible for passing this data to dataset . give instance for correct row of dataset and data in data table . use one gird view for...
9
by: AGP | last post by:
I've been scratching my head for weeks to understand why some code doesnt work for me. here is what i have: dim sVal as string = "13.2401516" dim x as double x = sVal debug.writeline ( x)
2
Thew
by: Thew | last post by:
<script language="javascript" type="text/javascript"> function spoilershow(){ document.getElementById("spoiler").style.visibility='visible'; document.getElementById("show").value='close';...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.