I have a collection of buttons and when I click them I am trying to display the HTML from a different file. I tried dabbling in JQuery but I decided I want to try doing it with fetch
2 Answers
If you're using jquery, you can try to use .load() method:
$(content).load('content.php');
Or if you still want to use fetch method:
fetch('content.php')
.then(function(response) {
var html = response.text();
var parser = new DOMParser();
var doc = parser.parseFromString(html, "text/html");
content.innerHTML = doc.innerHTML;
});
fetch('content.php').then(res => res.text()).then(response => content.innerHTML = response);