Home Javascript JavaScript method createElement()



JavaScript method createElement()
Posted on: June 13, 2009 at 12:00 AM
This section illustrates you the use of JavaScript method createElement().

JavaScript method createElement()

     

This section illustrates you the use of JavaScript method createElement(). This method creates an instance of the element for the specified tag. It works only on Internet Explorer. In the given example, we let the user enter the name. As the user clicks the button, the name will get added to the specified table. Following code adds the text (i.e. entered name) into the container (i.e. table).

element2.appendChild(text);
element1.appendChild(element2); 
table.tBodies(0).appendChild(element1);

 

 

 

Here is the code:

<html>
<script>
function addValue(a) {
var element1 = document.createElement('tr');
var element2 = document.createElement('td');
var text = document.createTextNode(a);
var table = document.getElementById('t');
element2.appendChild(text);
element1.appendChild(element2); 
table.tBodies(0).appendChild(element1);
}
</script>
Name: <input type="text" name="a">
<input type="button" value="Add" onClick='javascript:addValue(a.value)'>
<table id="t" border="1">
<tr><th>Employee Name</th></tr>
</table>
</html>

Output will be displayed as:

As you enter the name and click the button, the entered name will get added to the table:

Download Source Code:

     

Related Tags for JavaScript method createElement():
cmethodtaginstancethiselementcreateifforieciepeceinstamntesspecemmesspatiseassthsto


More Tutorials from this section

Ask Questions?    Discuss: JavaScript method createElement()  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.