appendChild with custom objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shawn Modersohn

    appendChild with custom objects

    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,progr am,dated,author ,url){
    this.title=titl e;
    this.program=pr ogram;
    this.dated=date d
    this.author=aut hor;
    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=documen t.createElement ("P")
    newElem.appendC hild(show1.url)
    document.getEle mentById("right I").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(sho w1.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.

  • Martin Honnen

    #2
    Re: appendChild with custom objects



    Shawn Modersohn wrote:

    [color=blue]
    > <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,progr am,dated,author ,url){
    > this.title=titl e;
    > this.program=pr ogram;
    > this.dated=date d
    > this.author=aut hor;
    > 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=documen t.createElement ("P")[/color]

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

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



    --

    Martin Honnen


    Comment

    Working...