Java Scipt

  1. On Page Script

    Adding internal JavaScript to HTML

    <script type="text/javascript"> //JS code class="code" goes here </script>
  2. External JS File

    Adding external JavaScript to HTML

    <script src="filename.js"></script>
  3. Functions

    JavaScript Function syntax

    function nameOfFunction(){
    // function body 
    }
  4. DOM Element

    Changing content of a DOM Element

    document.getElementById("elementID").innerHTML = "Hello World!";
  5. Creating Elements

    • createElement

      Create a new element

      document.createElement('div')
    • createTextNode

      Create a new text node

      document.createTextNode('some text here')
  6. Query/Get Elements

      The browser creates a DOM (Document Object Model) whenever a web page is loaded, and with the help of HTML DOM, one can access and modify all the elements of the HTML document

    • querySelector

      Selector to select first matching element

      document.querySelector('css-selectors')