DEV Community

Edison Ade
Edison Ade

Posted on

Learn about JavaScript Functions

What are functions?

Basically a set of codes in blocks that are reusable, and tells your application to perform a specific task once we call the function name.

Let us create one:
First create an HTML document to display what we create. In the head of your html document.


    <script src="script.js" defer></script>
 Then create a button in the body of the document
"button onclick = "clickMe()"
 <button onclick="clickMe()"> CLICK HERE</button>
 <div id ="click">


Enter fullscreen mode Exit fullscreen mode

Save this as index.html

Then we create the function in another file. Let us call that script.js

//basic function that allows you to click on a button and then display text when we click on the button

function clickMe(){
    me = document.getElementById('click')
    me.innerHTML = "SEE ME HERE"

<code>} </code>

Enter fullscreen mode Exit fullscreen mode

Save the file. Once you click on the button the text should appear.

Top comments (2)

vasilevskialeks profile image
Aleksandar Vasilevsk

Great post, I have written similar post week ago feel free to check it here

buzzedison profile image
Edison Ade

Oh cool. Will check it out. Thanks.