Skip to content

Instantly share code, notes, and snippets.

@selfsame
Created September 28, 2017 13:24
Show Gist options
  • Save selfsame/70f476be7797194f3c8da599e4c85295 to your computer and use it in GitHub Desktop.
Save selfsame/70f476be7797194f3c8da599e4c85295 to your computer and use it in GitHub Desktop.
var get_json = function(url, cb){
var xmlhttp = new XMLHttpRequest()
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var res = JSON.parse(this.responseText)
cb(res)}}
xmlhttp.open("GET", url, true)
xmlhttp.send()}
var make_element = function(tag, opts){
opts = opts || {}
var el = document.createElement(tag)
if (opts["class"]) {el.setAttribute("class", opts["class"])}
if (opts["id"]) {el.setAttribute("id", opts["id"])}
if (opts["href"]) {el.setAttribute("href", opts["href"])}
if (opts["text"]) {el.textContent = opts["text"]}
return el}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment