Random quote machine!

Random quote machine!
0.0 0

#1

Hey guys, i need a little help. If you open my code pen, you will se that both my buttons (generate quote, and share quote), they both generate a quote. How do i select a specific button in javascript? one should generate it, and other should share it on twitter. Any clues?

here is my pen:


#2

You could select a button based on ID.
https://www.w3schools.com/tags/att_global_id.asp
http://api.jquery.com/id-selector/

Demo

https://jsfiddle.net/s9amtq5k/6/


#3

well yes, but if you look my code, you can see that i have UL classes, and i, e subclasses…how can i change from there? i dont want to change everything to <button :confused:


#4

The code below is causing both anchors to change the quote,

  $(".btn").on("click", function() {
    generateQuote();
  });

There are a couple of ways to make one anchor generate a new quote and the other tweet the quote.
One way is to do something similar to what @Quickz suggested and add an unique ID to each anchor. Then, you would have create a click event handler for each id (one to generate the quote and the other tweet the quote).


#5

btw, if i try to <button, and if i try to put some of my bootstrap icons in it, it doesnt work (twitter icon is not showing)btnbtn


#6

BTW - Looking at your latest screenshot, there is no such element as e. I think you meant to put an i element instead of an e element.


#7

yes i know that, and thats what i am trying to change, but i try to keep my UL and Li classes, instead of changing everything to <button, but i dont know where can i put an ID, so i can sepereate them. feeling lost a bit


#8

ah ok i solved it, thank you guys for helping.


#9

I did not say anything about adding a button element.