Posts

Showing posts from March, 2017

Introduction of JavaScript

JavaScript is the programming language of HTML and the Web. JavaScript is easy to learn. This tutorial will teach you JavaScript from basic to advanced. JavaScript Can Change HTML Content One of many JavaScript HTML methods is   getElementById() . example: <!DOCTYPE html> <html> <body> <h1>What Can JavaScript Do?</h1> <p id="demo">JavaScript can change HTML content.</p> <button type="button" onclick='document.getElementById("demo").innerHTML = "Hello JavaScript!"'>Click Me!</button> </body> </html>

javascript in html

To insert a JavaScript script in an HTML page, you use the   <script> ... </script>   tag.   Don't forget the closing </script> tag!   Now get ready to fire off your text editor of choice and let's get coding! Let's start with a basic HTML page, like this one: <!DOCTYPE html> <html> <head> <title>My first JavaScript page</title> </head> <body> </body> </html> The JavaScript script is inserted either in the HTML page itself or in a separate file. Embed JavaScript in the HTML page The <script> tag and its   type   attribute tell the browser: "Hey, browser! There's a script coming up, and it's a JavaScript script." You can do this either in the <head> section, as follows: <!DOCTYPE html> <html> <head> <title>My first JavaScript page</title> <script type="text/ja

Events in Javascript

What are events? Events   are occurrences taking place in the context of the   interactions   between   web server ,   web browser , and   web user . onClick   event: triggered by you as you click the link; onUnload   event: triggered by the web browser as it leaves the current web page; onLoad   event: triggered by the browser as the new web page content is loaded. Which events should I focus on from a JavaScript point of view? It all depends on the JavaScript program you're writing, that is, on the objectives you want to achieve with your script. However, the most common events you're likely to deal with in your JavaScript are: onLoad/onUnload ; onClick ; onSubmit   (triggered by the user submitting a form); onFocus / onBlur   (triggered by a user as, for example, she clicks in a textbox or clicks away from a textbox respectively); onMouseOver / onMouseOut   (triggered by the user moving the mouse over or away from an HTML element respectively). There are other events that mi

Variables and Constants in javascript

Variables   and   constants   are like containers where you store data and values for processing in JavaScript. The difference between a   variable   and a   constant   is this: once you give a   value   to a   constant the value is meant to be kept unchanged   throughout the script. In all circumstances where you reasonably foresee that the   original value is modified   through the script, by all means use a   variable   as your storage room. In fact,   you're going to use variables most of the times . In this lesson, you're going to learn: how to   create   variables and constants; how to   assign   values to variables and constants; how to   use   variables in your code; how to   name   variables and constants correctly. How to create variables and constants You   declare , that is, create variables and constants in a similar way. Here's how you   declare a variable : /*To declare a variable you give it a name preceded by the JavaScrip

Operators in javascript

In the previous lesson you already employed an   assignment operator ( = )   and an   arithmetic operator , specifically the   multiplication operator ( * ) , to write a basic JavaScript shopping cart script. We can easily see that to do something useful with JavaScript, we need a way to   manipulate   data and variables. We do this with   operators . In this lesson you are going to learn how to use: arithmetic operators ; the + sign to concatenate text (concatenation operator) ; comparison operators ; logical operators . Also, you'll get plenty of opportunities to practice coding with variables. Let's get started! Arithmetic operators As you might have guessed,   arithmetic operators   are used to   perform arithmetic operations between values or variables . Here's a table for your reference. If   x = 20, y = 5, and z = result , we have: Operator Java Script Example Result Addition: + z = x + y z = 25 Subtraction: - z = x - y z = 15 Multiplication: