Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-16-2011, 01:57 AM   PM User | #1
NKeuxmuis
New Coder

 
Join Date: Feb 2011
Posts: 23
Thanks: 4
Thanked 0 Times in 0 Posts
NKeuxmuis is an unknown quantity at this point
How can I swap the order of these two sections?

In the following code I display two buttons in the randommember div. I then append the randommember div with contents of the rana variable. This variable stores information related to a featured member and displays it as a link. Basically buttons appear on screen which are then followed by the featured member. But I would like to switch this around and have the featured member appear followed by the buttons. How can I do this? Obviously I can't put the buttons into the rana variable because then these become a link also removing the links functionality. Does anybody have any ideas how I can solve this problem. I am new to Javascript so please be gentle.

Code:
r = Math.floor(Math.random() * x.length);

function randommember() {
    name = (x[r].getElementsByTagName("name")[0].childNodes[0].nodeValue);
    sex = (x[r].getElementsByTagName("sex")[0].childNodes[0].nodeValue);
    seeking = (x[r].getElementsByTagName("seeking")[0].childNodes[0].nodeValue);
    image = (x[r].getElementsByTagName("imgname")[0].childNodes[0].nodeValue);
    rana = document.createElement('a');
    aIdName = 'random';
    ahref = '#';
    aclick = 'show(' + r + ')';
    rana.setAttribute('id', aIdName);
    rana.setAttribute('href', ahref);
    rana.setAttribute('onclick', aclick);
    rana.innerHTML = "<h3>Featured Member</h3><br /><img src='images/" + image + ".gif' /><br /><br />Name: " + name + "<br />Sex: " + sex + "<br />Seeking: " + seeking;
    document.getElementById("randommember").innerHTML = "<input type='button' onclick='previous()' value='<<' /><input type='button' onclick='next()' value='>>' /><br />";
    document.getElementById("randommember").appendChild(rana);

}
NKeuxmuis is offline   Reply With Quote
Reply

Bookmarks

Tags
appendchild, innerhtml, javascript, order, setattribute

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:47 PM.


Advertisement
Log in to turn off these ads.