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

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

#1

Hi folks,

I’ve hit a bit of a brick wall with my random code generator: http://codepen.io/l3w15/pen/qRYPpG

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’, ‘https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=’ + a);
link.setAttribute(‘target’, ‘_blank’);
var birdie = document.createElement(‘i’);
birdie.setAttribute(‘class’, “fa fa-twitter”);
birdie.setAttribute(‘aria-hidden’, ‘true’);
tweet.appendChild(link);
link.appendChild(birdie);

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:


#2

try this:

I made these for my high school students.


#3

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


#4

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)


#5

Thanks I’ll try that!