How fetch api data and display it on HTML
Display the variable to an HTML element content using innerHTML
property
This tutorial will show you how to use all three ways to display JavaScript variables in HTML pages. Let’s start with using document.getElementById() method.
Every single HTML element has the innerHTML
property which holds the content of that element. The browser allows you to manipulate the innerHTML
property by using JavaScript by simply assigning the property to a different value.
You can replace the content of <span>
tag by first retrieving the element using its identifier. Since the element <span>
has an id
attribute with the value of joke, you can use document.getElementById
method to retrieve it and change its innerHTML
property.
And that’s how you can display JavaScript variable values using innerHTML
property.
Here final resultApi Display Jokes by chuck
phew phewJoke: