473,406 Members | 2,371 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,406 software developers and data experts.

Dynamically create image for <li>

I want to create image on list <li> during runtime.

Please help.

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. function myFunction() { 
  2. var ul = document.getElementById("list");
  3. var li = document.createElement("li");
  4. li.appendChild(document.createTextNode(<img src=picture.jpg)); // I want the image to go here. any suggestion?
  5. ul.appendChild(li);
Oct 30 '14 #1
2 1705
Dormilich
8,658 Expert Mod 8TB
erm, you are aware that document.createTextNode() creates a literal text no matter what you put in (hence the name!) ?

the solution: create an image element (just like you did with the <li> element)
Oct 30 '14 #2
jmrker
17
One possible, of many available, solution...

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title> HTML5 page </title>
  6. </head>
  7. <body>
  8. <ul id="list"></ul>
  9.  
  10. <script type="text/javascript">
  11. function myFunction(imageName,imageText) { 
  12.   var ul = document.getElementById("list");
  13.   var li = document.createElement("li");
  14.   var img = document.createElement('img');
  15.   img.setAttribute("src", imageName);
  16.   img.setAttribute("width", "150");
  17.   img.setAttribute("width", "125");
  18.   img.setAttribute("alt", imageText);
  19.  
  20.   li.appendChild(img); // I want the image to go here. any suggestion?
  21.   ul.appendChild(li);
  22. }
  23. window.onload = function() {
  24.   myFunction("http://www.nova.edu/hpd/otm/pics/4fun/11.jpg","Exhausted");
  25.   myFunction("http://www.nova.edu/hpd/otm/pics/4fun/21.jpg","Angry");
  26.   myFunction("http://www.nova.edu/hpd/otm/pics/4fun/31.jpg","Embarrassed");
  27. }
  28. </script>
  29.  
  30. </body>
  31. </html>
  32.  
Jan 1 '15 #3

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

Similar topics

2
by: Curtis Wellborn | last post by:
Hey, I was wondering if there is any way in the designer to put my Icons(which i have 200 in three different folders) into an ImageList with out doing it one by one in the add image. This will...
2
by: Newbie | last post by:
Hello! I'm trying to figure out how to do the following: I need to show a table (perhaps using DataGrids, repeaters or others) for each salesperson in the sales dept. But the no. of tables...
1
by: Just close your eyes and see | last post by:
is there any control in .NET like image list but it can store files from any type, not only image format ? thx all :)
5
by: Markus Stehle | last post by:
Hi all! I have asp.net web application that uses static impersonation. Is it possible to change the impersonated user during runtime? Within some parts of my application I would like to...
3
by: Sampson | last post by:
I have a question about enumeration and how to populate them during runtime. I am using vb.net but will happily take any advice in c# as well. Here is an example to help illustrate what I am...
4
by: murali pannala via .NET 247 | last post by:
(Type your message here) -------------------------------- From: murali pannala i would want to create an object dynamically. i.e i hold my class name in a variable only.and by passing this...
4
by: John Daly | last post by:
Does anyone know how to create an image (JPEG) from an HTTPResponse object? I am working on system that has a map pop up from our GIS department. I want create an image at runtime from this popup...
2
by: ruthboaz | last post by:
Hi, I am creating the following query during run-time. Dim ctl As Control Dim varItem As Variant Dim strSQL As String Dim stDocName As String
2
by: Christian Muggli | last post by:
can someone explain me how to create a app.config file during runtime? i see two ways: - add a skeleton of an app.config file to the exe/dll and extract it during runtime as a resource and...
0
by: Xeevis | last post by:
Hey, I have kinda complicated problem. I have console application which itself compile Scripts Library during runtime and then it uses it (allow ppl to drop in plain .cs files without need to build...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
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,...
0
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...

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.