473,545 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How will create Unordered List dynamically using JavaScripe

3 New Member
Suppose I have an Unordered List in my HTML file:


[HTML]<html>
<head>
<SCRIPT LANGUAGE="JavaS cript">
function remove(){
//code to remove the old elements
var d=document.getE lementById("for um");
d.parentNode.re moveChild(d);
//code to add new elements
var li =document.creat eElement("li");
var p = document.create TextNode('Hello ');
li.appendChild( p);
d.insertBefore( li, 1); //this is not working
}
</SCRIPT>
</head>
.....
<ul id="forum">
<li>JavaScrip t</li>
<li>Forum</li>
</ul>

....
<input type="button" onclick="remove ()" >
</html>[/HTML]


Now, what is the code I have to write to remove to add new elements after removing all the parent elements?

Plz sort out my problem... Thanks in advance.

regards,
Ranjan Y
Mar 5 '08 #1
5 11572
gits
5,390 Recognized Expert Moderator Expert
you could use the replaceChild() method for that purpose ...

kind regards
Mar 5 '08 #2
ranyeng
3 New Member
you could use the replaceChild() method for that purpose ...

kind regards

Hi Gits,
Thanks for ur quick reply. What I exactly want is...

Step 1: Remove all the existing elements of the unordered list
Step 2: Start adding new elements
Mar 5 '08 #3
gits
5,390 Recognized Expert Moderator Expert
as i said ... you just could create a new ul- and its li-nodes and replace the current one or you shouldn't use removeChild fo the ul-node and set its innerHTML to an empty string instead and append the li-elements you create directly to the existing ul-node ...

kind regards
Mar 5 '08 #4
ranyeng
3 New Member
as i said ... you just could create a new ul- and its li-nodes and replace the current one or you shouldn't use removeChild fo the ul-node and set its innerHTML to an empty string instead and append the li-elements you create directly to the existing ul-node ...

kind regards
Thanks Gits... I have got the idea and my problem has been addressed.
Mar 5 '08 #5
gits
5,390 Recognized Expert Moderator Expert
post back when you encounter problems with it :)

kind regards
Mar 5 '08 #6

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

Similar topics

3
3821
by: Kevin Campbell | last post by:
Say I have the following XML spec: <Book> <Title /> <Author /> <ISBN /> <Description /> </Book> Title, Author, ISBN and Description may appear in any order. Title,
1
30935
by: Nathan Sokalski | last post by:
I want to add a bulleted list to my document in ASP.NET. I know the HTML code, and I have used the HtmlGenericControl, but is there an ASP.NET object that can generate UL and LI tags from a set of ListItem objects, or maybe some other collection? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
6
4733
by: Rich | last post by:
Hello, I want to simulate the dynamic thumbnail display of Windows Explorer (winxp) on a form or pannel container. If I place a picture box on my container form/pannel and dimension it to the size of a thumbnail and set the sizemode to Stretch -- I get one thumbnail. I want to retrieve all the picture files (jpg, bmp) in a directory into...
1
9897
by: michael | last post by:
Good Morning, I have an unordered list similar to: <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul>
5
2290
by: ibiza | last post by:
Hi all, I have a question which I have no ideal of the answer...I am currently working on a web application and at some time, I have a string representing a short text. This could be a simple example : "This is my list :\n\r-list item 1\n\r-list item 2\n\r-list item 3\n\r\n\rThis was a great list." Let's say this outputs like that :
1
1086
by: simplico | last post by:
I'm creating an unordered list that fits in a defined width on the left side of the page. It works fine in FF but IE is another story. Here is a watered-down version of the code: <html> <head> <title>Untitled</title> <style type="text/css"> * {margin: 0px; padding: 0px; border: 0px; border: 1px solid
3
3476
by: User | last post by:
Hi, Is it possible to transform Ordered/Unordered list into navigation dropdown menus? Is this effect achieved by CSS? or via Javascript? PLease advise Thanks.
2
2168
by: torweb | last post by:
I'm using an image for an unordered list, which works fine. The problem is, the image is also appearing in my numbered "ordered list." Here is my code for the unordered list:...and thanks in advance: ul { font-family: Arial; font-size: 12px; color: #424E51; font-style: normal line-height: 17px; font-weight: normal; font-variant: normal;
2
2215
by: asc4john | last post by:
When including an unordered list in an unordered list: Should it be included as a "list" item as in: <ul><liitem</ li><ul.... </ul<liitem</li</ul> or included in the LI element as in: <ul><liitem</li<li<ul... </ul></li></ul>? or does it matter?
0
7468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7808
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7757
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5329
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.