Skip to content
Sign upLog in
← Back to Community

Making A Simple Front End API

Profile icon

Making a Simple Front End API Tutorial

Great, thanks for coming to my tutorial! For once, this tutorial will not be for upvotes and cycles. :P
So first of all, you need to know about DOM in js. If not, check out a tutorial.
Let’s start. First, lets write a function to make elements.

function elt(element,text){ document.createElement(element).innerText = text }

Cool! But if we call our function (elt(‘h1’, ‘Hello’)) nothing happens. Thats because we didn’t append anything. Let’s write our second function:

function append(node) { document.appendChild(node) }

Sweet. Now we can call our function to append something like this:

Hello world!

append(elt(‘h1’,’Hello world!’))

Nice! But let me explain everything.
The elt function makes a new element, and then assigns the innerText property to the text in the argument. The append function just appends it to the body. We’re done here! For a bit more extendable option, see my ECA (I’m horrible at names, right? Comment if you agree) down below.

Profile icon
Profile icon

I am looking for it. Thank you for sharing
drift boss