Help with tweet button on Random Code Generator (appendChild / replaceChild)

Hi folks,

I’ve hit a bit of a brick wall with my random code generator:

I’m reasonably happy with it except that the way I’ve set up my newQuote() function in js means that you get a new font-awesome twitter bird in the button every time you generate a new quote. (The one furthest right tweets the newest quote, as you go left they hold the link for previous quotes). The relevant bit of javascript is:

var tweet = document.getElementById(‘tweet’);
var link = document.createElement(‘a’);
link.setAttribute(‘href’, ‘’ + a);
link.setAttribute(‘target’, ‘_blank’);
var birdie = document.createElement(‘i’);
birdie.setAttribute(‘class’, “fa fa-twitter”);
birdie.setAttribute(‘aria-hidden’, ‘true’);

As this function runs onload and onclick, I understand why it generates a new bird icon each time, but can’t seem to fix it… thought it should be possible to use replaceChild, but am getting frustrated after many failed attempts.

Any help greatly appreciated :slight_smile:

try this:

I made these for my high school students.

1 Like

Thanks MrSnowNB! Could you offer any more specific help with my query?

Do you need to set the class in JQuery when you can set it in HTML Bootstrap?

a href=’#’ class=‘btn btn-default btn-lg tweetQuote’>i class=“fa fa-twitter fa-fw” aria-hidden=“true”></iTweet Quote</a

(I removed some <> so you can see it)

Thanks I’ll try that!