appendChild with custom objects

  • Thread starter Shawn Modersohn
  • Start date
S

Shawn Modersohn

Firstly, thanks for all the help in here.

My code is:

<script type="text/javascript">
var img1= new Image(200,200)
img1.src="file://d:/datatools/c++/boat1.jpg"
var img2 = new Image(200,200)
img2.src="file://d:/datatools/c++/china1.jpg"

function art(title,program,dated,author,url){
this.title=title;
this.program=program;
this.dated=dated
this.author=author;
this.url=url;
}
var show1=new art("the boat", "photoshop", "Aug 2004", "Shawn
Modersohn", img1)
var show2=new art("China", "photoshop", "Aug 2004", "Pamela Phillips", img2)
function navigateTo(){
var newElem=document.createElement("P")
newElem.appendChild(show1.url)
document.getElementById("rightI").appendChild(newElem)
}
</script>

It is going to be a script that cycles images for a slideshow
presentation. I am not worrying quite yet about the if elses, the for
loops, and other such control structures.

What I want to know is how I can append both an image coupled with the
title etc. As I am sure most of you are aware, appendChild(show1.url +
show1.title) does not work. I am hoping to use css and declare #rightI
p img {block} and other such attributes to control presentation. I just
want to know how to get both the image and the title, author, etc, into
the div I want them to go in. As it is now, it works only well enough
to append the appropriate image. Thanks again for any help.
 
M

Martin Honnen

Shawn Modersohn wrote:

<script type="text/javascript">
var img1= new Image(200,200)
img1.src="file://d:/datatools/c++/boat1.jpg"
var img2 = new Image(200,200)
img2.src="file://d:/datatools/c++/china1.jpg"

function art(title,program,dated,author,url){
this.title=title;
this.program=program;
this.dated=dated
this.author=author;
this.url=url;
}
var show1=new art("the boat", "photoshop", "Aug 2004", "Shawn
Modersohn", img1)
var show2=new art("China", "photoshop", "Aug 2004", "Pamela Phillips",
img2)
function navigateTo(){
var newElem=document.createElement("P")

Well create what you need an append it e.g.
var img = document.createElement('img');
img.src = show1.src;
img.title = show1.title;
img.alt = ''
newElem.appendChild(img);

If you also want to display text then create a text node and append that too
var text = document.createTextNode(show1.dated);
newElem.appendChild(text);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top