To begin using JavaScript, you must write learn how to write a function. A function is a method that allows you to alter the webpage. This is done by placing an 'onclick' attribute inside of your HTML element. There is many different types of functions you can write, from very basic to complex functions. Like CSS, your functions can be declared within your HTML page or on an external JavaScript sheet. I have created a very simple function, see below:
In the first image you can see the code and the webpage when it initially loads. The second image shows you what happens when the button is clicked. When the button is clicked, it runs the function 'displayDateTime'. Within this function I have a statement which looks for the id 'demo'. Once this is found, it places the date and time in the element which has that id. The date and time is found using a pre-defined class called date(). This is a pre-written so you don't have to write it.
No comments:
Post a Comment