Introduction to jQuery
So you know html , css and javascript , Now lets know what is jQuery?. jQuery is a cross-platform , open source , client side javascript library. Its was Created by John Resig in 2005 an released in 2006 .
Why to Use jQuery?
- It Simplifies the interaction between html and javascript.
- It can be used to handle events purely in JavaScript. So, the HTML tags and JavaScript can be completely separated.
- The JavaScript engines of different browsers differ slightly, so JavaScript code that works for one browser may not work on the other. It handles all these cross-browser inconsistencies and provides a consistent interface that works across different browsers.
- Offers DOM manipulation based on CSS selectors.
- Has Tons of Plugins.
Usage Examples
First you need to include the jQuery file which is a single javascript file , you can use the CDN hosted file or download the file and include
<script src="jquery.js"></script>
<script src="code.jquery.com/jquery-1.11.1.min.js"></script>
‘$’ is a jQuery alias which is used . If there are other libraries you can use ‘.noConflict()’ mode which relinquishes control of $.The syntax goes like this $(selector).action().
<script>
$(document).ready(function(){
$('p').click ( function() {
$(this).css('color','blue');
});
});
</script>
The above code will change text color of paragraph tag to blue on click.’this’ is a special keyword that is used in methods to refer to the object on which a method is being invoked.