Practical jQuery Skills Every Developer Should Know

What You'll Learn Today
You've already covered jQuery's basic syntax and AJAX up to this point.
This session will focus on features frequently used in actual company development environments.
The following topics will be covered:
Event Delegation
Using data()
serialize()
Difference between prop() and attr()
Scroll Event
Resize Event
trigger()
AJAX Global Events
Practical Tips
These features appear frequently in real-world projects.
Event Delegation
Dynamic elements often don't respond to standard click() events.
For example:
$(".delete").click(function(){
alert("삭제");
});
After adding comments via AJAX, newly created delete buttons may not function.
This is where event delegation comes in handy.
Event Delegation Using on()
$(document).on(
"click",
".delete",
function(){
alert("삭제");
}
);
This approach ensures all future buttons will also trigger the event.
It's the most common method used in forums, comments sections, and e-commerce sites.
Using data()
HTML
<button
class="view"
data-id="10"
>
보기
</button>
JavaScript
$(".view").click(function(){
var id=$(this).data("id");
console.log(id);
});
This is commonly used to store post IDs or product numbers.
Difference Between attr() and data()
attr()
$(this).attr("data-id");
data()
$(this).data("id");
In practice, developers prefer using data() more often.
This is because it's more readable and convenient to use.
serialize()
Sends entire form in one submission.
HTML
<form id="joinForm">
<input name="userid">
<input name="password">
</form>
JavaScript
$.ajax({
url:"join.php",
type:"POST",
data:$("#joinForm").serialize()
});
No need to handle each input individually.
This is the most common method used in registration and login pages.
serializeArray()
Returns data as an array format.
var data=$("#joinForm")
.serializeArray();
console.log(data);
The result appears like:
[
{
name:"userid",
value:"hong"
},
{
name:"password",
value:"1234"
}
]
as shown above.
prop()
Use prop() for checkboxes and radio buttons.
Check status
$("#agree").prop("checked");
Check the box
$("#agree").prop(
"checked",
true
);
Uncheck the box
$("#agree").prop(
"checked",
false
);
Difference Between attr() and prop()
Attribute
attr()
Property
prop()
Use prop() for checkboxes, disabled states, and selected options.
scroll() Event
Executes when scrolling occurs.
$(window).scroll(function(){
console.log(
$(window).scrollTop()
);
});
Allows you to retrieve current scroll position.
Creating a 'Back to Top' Button
$(window).scroll(function(){
if(
$(window).scrollTop()>300
){
$("#topBtn").fadeIn();
}else{
$("#topBtn").fadeOut();
}
});
Commonly used across many websites.
resize()
Executes when browser window size changes.
$(window).resize(function(){
console.log(
$(window).width()
);
});
Frequently used in responsive web design.
trigger()
Forces an event to execute.
$("#btn").trigger("click");
The click event executes without actually clicking the button.
triggerHandler()
Executes only on the current element.
$("#btn")
.triggerHandler("click");
No event bubbling occurs.
AJAX Global Events
Executes when all AJAX requests begin:
$(document).ajaxStart(function(){
$("#loading").show();
});
Executes when all AJAX requests finish:
$(document).ajaxStop(function(){
$("#loading").hide();
});
Commonly used for loading screens.
$.ajaxSetup()
Sets default AJAX configuration.
$.ajaxSetup({
cache:false
});
Allows common options to be used across multiple AJAX requests.
Using delay()
$("#msg")
.fadeIn()
.delay(2000)
.fadeOut();
Frequently used for displaying notification messages.
Debounce Concept
Calling AJAX on every keystroke in search fields can burden the server.
Therefore, many developers implement a method that only triggers AJAX when input pauses for a certain time.
This is called Debounce.
Here's a simple example:
var timer;
$("#keyword").keyup(function(){
clearTimeout(timer);
timer=setTimeout(function(){
console.log("검색");
},300);
});
This technique is commonly used in real-time search features.
Practical Example 1
Select all checkboxes
$("#all").click(function(){
$("input[type=checkbox]")
.prop(
"checked",
$(this).prop("checked")
);
});
Practical Example 2
Product detail view
$(".product").click(function(){
var id=$(this).data("id");
location.href=
"view.php?id="+id;
});
Practical Example 3
Submit entire form
$("#save").click(function(){
$.post(
"save.php",
$("#form").serialize()
);
});
Practical Example 4
Scroll to top button
$("#topBtn").click(function(){
$("html, body").animate(
{
scrollTop:0
},
500
);
});
Commonly used in e-commerce sites and blogs.
Practical Tips
Get into the habit of using on() for events.
This handles elements created dynamically as well.
Always include error handling in AJAX calls.
This makes it easier to identify exceptions.
Make active use of serialize().
It significantly simplifies form submission code.
Distinguish between prop() and attr() usage.
prop() is the standard for checkboxes.
Scroll events execute frequently.
If needed, consider using debounce or throttle to optimize performance.
Common Mistakes Beginners Make
Using click() only
Dynamically created buttons may not function properly.
Get into the habit of using on().
Controlling checkboxes with attr()
Use prop() instead for checked state.
Not using serialize()
Form data handling becomes more complicated as the form grows larger.
Using serialize() makes it much simpler.
Practice Assignments
Assignment 1
Create a button that triggers clicks even when dynamically generated using event delegation.
Assignment 2
Submit a registration form using serialize().
Assignment 3
Create a button that appears when scrolling past 500px.
Assignment 4
Automatically trigger a button click using trigger().
Assignment 5
Implement debounce in a search field so that searching only occurs after 300ms of no input.
Key Takeaways
Use on() for event delegation implementation.
data() provides easy access to HTML data-* attributes.
serialize() sends form data in one submission.
prop() controls checkbox and radio button states.
scroll() and resize() respond to user environment changes.
trigger() forces event execution.
AJAX global events simplify loading screen implementation.
Debounce reduces unnecessary event calls, improving performance.
Closing
This session covered jQuery features frequently used in real-world projects.
The techniques you've learned today aren't just basic syntax—they're practical skills used daily in company development projects.
Especially event delegation, serialize(), data(), prop(), and debounce are important functions that boost productivity and make maintenance easier.
In the next session, we'll work on a mini project and real-world implementation to combine all the techniques learned so far. We'll build a forum and user management interface using jQuery.
FAQ
Why use on() instead of click() for events?
on() allows handling dynamically created elements, while click() only works with existing elements when the code is executed.
What's the difference between prop() and attr()?
prop() controls current state (like checked status), while attr() accesses HTML attributes. Use prop() for checkboxes and radio buttons.
Korean Source
This article is an English localization of a Korean-language report from BlogScore. Original: [Jquery 강좌] 11강 실무에서 자주 사용하는 jQuery 기능