jQuery tutorial for beginners
Author
May 24, 2016
What is jQuery?
jQuery is a lightweight, “write less, do more”, JavaScript library. jQuery is a fast, small, and feature-rich JavaScript library. It makes 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 is absolutely amazing. It’s cross-browser, easy to learn, and makes adding interactivity to your website a breeze.
How to setup jQuery file with html
Before we can do anything, we need to establish our file and link it to our HTML document. First, we will create our plugin file and put it in the directory of our website. It is traditional to start our filename with jQuery, followed by the actual plugin name, so we will call this jquery-hello.
Let us create an index/ file and a folder by the name of js.
jQuery CDN
If you don’t want to download and host jQuery yourself, you can include it from a CDN (Content Delivery Network).
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js”></script>
jQuery Syntax
Basic syntax is: (selector).action()
1. A sign to define/access jQuery
2. A (selector) to “query (or find)” HTML elements
3. A jQuery action() to be performed on the element(s)
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”.
jQuery Event
| Mouse Events | Keyboard Events | Form Events | Document/Window Events |
| Click | Keypress | submit | load |
| Dblclick | Keydown | change | resize |
| Mouseenter | Keyup | focus | scroll |
| Mouseleave | blur | unload |
jQuery Events
click()
The function is executed when the user clicks on the HTML element.
The following example says: When a click event fires on a <p> element; hide the current <p> element:
$(“p”).click(function(){
$(this).hide();
});
dblclick()
The dblclick() method attaches an event handler function to an HTML element.
The function is executed when the user double-clicks on the HTML element:
$(“p”).dblclick(function(){
$(this).hide();
});
mouseenter()
The mouseenter() method also attaches an event handler function to an HTML element.
The function is executed when the mouse pointer enters the HTML element:
$(“#p1”).mouseenter(function(){
alert(“You entered p1!”);
});
mouseleave()
The mouseleave() method too attaches an event handler function to an HTML element.
The function is executed when the mouse pointer leaves the HTML element:
$(“#p1”).mouseleave(function(){
alert(“Bye! You now leave p1!”);
});
mousedown()
The event handler attached by mousedown()
is executed, when the left, middle or right mouse button is pressed down, while the mouse is over the HTML element:
$(“#p1”).mousedown(function(){
alert(“Mouse down over p1!”);
});
mouseup()
The event handler attached by mouseup ()
is executed, when the left, middle or right mouse button is pressed down, while the mouse is over the HTML element:
$(“#p1”).mouseup(function(){
alert(“Mouse up over p1!”);
});
hover()
The hover() method takes two functions and is a combination of the mouseenter() and mouseleave() methods.
The first function is executed when the mouse enters the HTML element, and the second function is executed when the mouse leaves the HTML element:
$(“#p1”).hover(function(){
alert(“You entered p1!”);
},
function(){
alert(“Bye! You now leave p1!”);
});
focus()
The focus() method attaches an event handler function to an HTML form field.
The function is executed when the form field gets focus:
$(“input”).focus(function(){
$(this).css(“background-color”, “#cccccc”);
});
blur()
The blur() method too attaches an event handler function to an HTML form field.
The function is executed when the form field loses focus:
$(“input”).blur(function(){
$(this).css(“background-color”, “#ffffff”);
});
On()
The on() method attaches one or more event handlers for the selected elements.
Attach a click event to a <p> element:
$(“p”).on(“click”, function(){
$(this).hide();
});
Attach multiple event handlers to a <p> element:
$(“p”).on(
{ mouseenter: function(){
$(this).css(“background-color”, “lightgray”);
},
mouseleave: function(){
$(this).css(“background-color”, “lightblue”);
},
click: function(){
$(this).css(“background-color”, “yellow”);
}
});
Recent Posts
-
The Hybrid Advantage in Salesforce QA20 May 2026 Blog -
CI/CD in Salesforce: Role of QA in DevOps Pipeline19 May 2026 Blog -
Reasons Why Addiction Treatment Centers should consider leveraging Salesforce as a CRM18 May 2026 Blog -
Insights on employee engagement15 May 2026 Blog -
AI Governance Why Businesses Need an AI Strategy Before Implementing AI14 May 2026 Blog -
Salesforce Agentforce: Revolutionizing AI with Autonomous Agents13 May 2026 Blog -
Salesforce Headless 360 Guide | Mirketa13 May 2026 Blog -
Salesforce Custom Permissions12 May 2026 Blog -
Salesforce Education Cloud – Time is Now11 May 2026 Blog -
Top Salesforce Performance Optimization Techniques for Large Enterprises08 May 2026 Blog -
AI Orchestration for Enterprises: Scale Smarter, Faster, and Securely08 May 2026 E-Book -
Stress is always on a vacation @ Mirketa08 May 2026 Blog -
UiPath RPA with AI Capabilities in Salesforce07 May 2026 Blog -
The ROI of AI in Enterprise Applications06 May 2026 Blog -
Rethinking Enterprise Quoting in Salesforce28 Apr 2026 Blog -
Integration Testing with Data Warehouse27 Apr 2026 Blog -
Salesforce Nonprofit Cloud vs NPSP: 2026 Comparison Guide24 Apr 2026 Blog -
Top Use Cases of Salesforce Experience Cloud for Businesses23 Apr 2026 Blog -
How Salesforce Nonprofit Cloud is Transforming Fundraising, Grant Management & CRM in 202622 Apr 2026 Blog -
Get Proactive with Salesforce-Mirketa’s Vaccine Cloud Solutions19 Apr 2026 Blog