60 likes | 69 Views
The programs in this language are called scripts. They can be written right in the HTML and execute automatically as the page loads. Scripts are provided and executed as a plain text. They donu2019t need a special preparation or a compilation to run.
E N D
WELCOME TO DUCAT INDIA Introduction to JavaScript 70-70-90-50-90 info@ducatindia.com
JavaScript was initially created to make webpages alive. The programs in this language are called scripts. They can be written right in the HTML and execute automatically as the page loads. Scripts are provided and executed as a plain text. They don’t need a special preparation or a compilation to run. In this aspect, JavaScript is very different from another language called Java. At present, JavaScript can execute not only in the browser, but also on the server, or actually on any device where there exists a special program called the JavaScript engine. The browser has an embedded engine, sometimes it’s also called a JavaScript virtual machine. • Different engines have different codenames, for example: • V8 – in Chrome and Opera. • SpiderMonkey – in Firefox. • …There are other codenames like Trident, Chakra for different versions of IE, ChakraCore for Microsoft Edge, Nitro and SquirrelFish for Safari etc.
JavaScript Can Change HTML Content One of many JavaScript HTML methods is getElementById(). This example uses the method to find an HTML element (with id=demo) and changes the element content (innerHTML) to Hello JavaScript: document.getElementById("demo").innerHTML = "Hello JavaScript"; JavaScript Can Change HTML Styles (CSS) Changing the style of an HTML element, is a variant of changing an HTML attribute: document.getElementById("demo").style.fontSize = "35px"; or document.getElementById('demo').style.fontSize = '35px';
JavaScript Can Hide HTML Elements Hiding HTML elements can be done by changing the display style: document.getElementById("demo").style.display = "none"; Or document.getElementById('demo').style.display = 'none'; JavaScript Can Show HTML Elements Showing hidden HTML elements can also be done by changing the display style: document.getElementById("demo").style.display = "block"; Or document.getElementById('demo').style.display = 'block';
In HTML, JavaScript code must be inserted between <script> and </script> tags. <script> document.getElementById("demo").innerHTML = "My First JavaScript"; </script> JavaScript Functions and Events A JavaScript function is a block of JavaScript code, that can be executed when called for. For example, a function can be called when an event occurs, like when the user clicks a button. JavaScript in <head> or <body>
THANK YOU 70-70-90-50-90 info@ducatindia.com