Random quote generator (Problem)

Random quote generator (Problem)
0

#1


This is my code and citation and year are optional properties of quotes array but citation and year are not showing when I click show another quote button.


#2
$('.citation').text (""+ citation_text);
$('.year').text(""+ year_text);

There are no such elements on your page. You don’t have anything with the class of citation or year, so you are trying to set the text content of elements that do not exist.


#3

So how can I do this then? Thanks.


#4

In your HTML, you need to add elements in the place where you want the year and citations to be, and give them the appropriate classes. You already have a year and source in your HTML, so if that is where you want them to appear, each can be wrapped in a span with that class, but you’re going to do something else.

You could structure it similar to this:

<p>
 <span>the source</span>
 <span>the citation</span>
 <span>the year</span>
</p>

putting appropriate classes on each span.


#5

thanks. :slight_smile: