I have a single page dynamic webpage. When the user clicks some buttons the entire layout of the app changes.
My current approach to do this is, clear the entire contents of the page, and hard code each line of html that needs to be added.
In other words, I have a javascript/jquery script that clears everything and manually adds each element one by one. Rather than parsing a pre-existing file or something more clever.
I would like to have a template written in html and jinja (if possible), and just load that information. I.e, clear the entire contents of the page then set them to the template.
But I am unsure on how to do that.
This would be for example, an attempt at creating a page:
function setResume() { setElementToFile("MainText", "static/resume.txt"); $('head').empty(); $('head').append('<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>'); $('head').append('<link rel="stylesheet" type="text/css" href="static/general.css"/>'); $('head').append('<link rel="stylesheet" type="text/css" href="static/resume.css"/>'); $(".TopHeader").css("margin-left", "10%"); $("article").empty() var more_info = $('<div class="TopHeader"></div> id="SecondHead"'); more_info.append( $('<a target="_blank" href="https://github.com/Makogan">\ <img src="static/images/GitHub-Mark.png" width="64px" height="64px" alt="github">\ </a>')); more_info.append( $('<a target="_blank" href="https://gitlab.com/Makogan">\ <img src="static/images/gitlab_logo.png" alt="github" width="64px" height="64px">\ </a>')); more_info.append( $('<a target="_blank" href="https://www.linkedin.com/in/camilo-talero-3906a9167/">\ <img src="static/images/linkedin_logo.png" alt="github" width="64px" height="64px">\ </a>')); more_info.append( $('<a target="_blank" href="https://www.linkedin.com/in/camilo-talero-3906a9167/">\ <img src="static/images/mail.png" alt="github" width="64px" height="64px">\ </a>')); $(".TopHeader").after(more_info); clearButtons(); document.getElementById("resume_button").style.backgroundColor = "rgba(25, 129, 190, 0.7)"; } function clearButtons() { var x = document.getElementsByTagName("button"); var i; for (i = 0; i < x.length; i++) { var color = getComputedStyle(document.body).getPropertyValue('--button_background_color'); x[i].style.backgroundColor = color; } } function setElementToFile(elementID, file) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById(elementID).innerHTML = this.responseText; } }; xhttp.open("GET", file, true); xhttp.send(); }