jQuery Example

Hello, world! Example

Here is the jQuery first example:
<div id="divTest1"></div>  
<script type="type/javascript">  
$("#divTest1").text("Hello, world!");  
</script>
The above code have a div tag with the id of "divTest1" and $ shortcut to access jQuery. In this code select all elements with an id of "divTest1" and set its text to "Hello, world!". Use the following code if you want to do it in the plain JavaScript without the help of jQuery:
  1. <div id="divTest2"></div>
  2. <script type="text/javascript">
  3. document.getElementById("divTest2").innerHTML = "Hello, world!";
  4. </script>
If your HTML element didn't have an id then it would be even longer.

Example:

<!DOCTYPE html>  
<html>  
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  
<script>  
$(document).ready(function(){  
    $("button").click(function(){  
        $(".test").hide();  
    });  
});  
</script>  
</head>  
<body>    
<h2 class="test">this is the first Hello World! Program</h2>  
<p class="test">this is the first program</p>  
<button>Hello, world! </button>   
</body>  
</html>
Try Now