How to use jQuery

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. jQuery has changed the way that millions of people write JavaScript.

There are some of  corporate members that makes possible for the jQuery Foundation to continue work on JavaScript libraries and pushing the open web forward with events and participation in the standards process:

IBM    SAMSUNG    WordPress    famo.us

How jQuery Works

The jQuery syntax is made for selecting HTML elements and performing some action on the element, like $(selector).action() where $ sign is define/access, (selector) find HTML elements and action() fulfill on the element.

Examples:

$(this).hide() – hides the current element.
$(“p”).hide() – hides all p elements.
$(“.test”).hide() – hides all elements with class=”test”.
$(“#test”).hide() – hides the element with id=”test”.

Example  with  using  jQuery.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
 $("p").click(function(){
 $(this).hide();
 });
});
</script>
</head>
<body>

<p>click to disappear this text</p>
<p>click to disappear this text</p>
<p>click to disappear this text</p>

</body>
</html>

 
The good practice is wait for the document to be fully loaded before working with it and put the JavaScript code before the body of your document, in the head section.

Leave a Reply

Your email address will not be published.

*