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”);
}
});
Pranshu Goyal, Director of Products at Mirekta, states: “We envision DSM to be used by every small to a medium-sized organization dealing with bad data and want to get rid of duplicates easily with no cost. We have faced issues dealing with duplicates in our organization. That inspired us to make a solution that is not only simple to use but can be used widely to make the organization’s data clean to make them more efficient and productive. We want DSM to be a solution for every organization looking for duplicate management capability better than the Salesforce out-of-the-box solution with no additional cost.”
Recent Posts
-
AI for Nonprofits: Boosting Fundraising with Salesforce Einstein, Agentforce, and Smarter InsightsShape25 Mar 2025 Use-case
-
AI-Powered Vaccination Scheduling with Einstein Copilot & Predictive AI21 Mar 2025 Use-case
-
Leveraging AI to Enhance Sales Effectiveness13 Mar 2025 Use-case
-
Revolutionizing Manufacturing with AI: Predictive Maintenance, Supply Chain Optimization, and More11 Mar 2025 E-Book
-
NetSuite for Manufacturing: Streamlining Operations and Solving Key Challenges07 Mar 2025 Blog
-
How to Build Your First Agent in Salesforce Agentforce24 Feb 2025 Blog
-
ERP vs Salesforce Revenue Cloud: Which One is Right for Your Business?24 Feb 2025 E-Book
-
Revolutionizing Manufacturing with Salesforce: A Playbook for Efficiency & Growth18 Feb 2025 E-Book
-
Salesforce 2025 Game-Changing Trends You Need to Know28 Jan 2025 Blog
-
Agentforce 2.0: Everything You Need to Know About the Latest Update22 Jan 2025 Blog
-
The Ultimate Guide to NetSuite Development: Tools and Techniques10 Jan 2025 Blog
-
How Salesforce Nonprofit Cloud Transforms Fundraising Strategies10 Jan 2025 Blog
-
The Impact of Salesforce Development Partners on Small and Medium Businesses08 Jan 2025 Blog
-
Key Questions to Ask When Hiring a NetSuite Development Partner08 Jan 2025 Blog
-
Salesforce Agentforce Demystified: Your Essential Guide08 Jan 2025 Blog
-
Salesforce and NetSuite Integration: Driving Business Efficiency with Precision06 Jan 2025 Blog
-
Everest Group has positioned Mirketa as an Aspirant in the report24 Dec 2024 Press Release
-
Salesforce Einstein20 Dec 2024 E-Book
-
Order to Cash Cycle with NetSuite20 Dec 2024 E-Book
-
Empower Your Marketing Strategy with Salesforce Marketing Cloud's Automation Studio Activities13 Dec 2024 Blog
Categories
Featured by



