jQuery — Queues and Serialized Data

Image for post
Image for post
Photo by Levi Jones on Unsplash

jQuery is a popular JavaScript for creating dynamic web pages.

In this article, we’ll look at how to using jQuery in our web apps.


The jQuery.merge() method merges the contents of 2 arrays together into the first array.

For example, we can use it by writing:

const arr = $.merge([0, 1, 2], [2, 3, 4])

Then arr is:

[0, 1, 2, 2, 3, 4]


The jQuery.noConflict() method relinquishes jQuery’s control of the $ variables.

We can use it by writing:

jQuery( "div p" ).hide();

We call noConflict .

Then we can invoke jQuery with jQuery instead of $ .


The jQuery.noop() method returns an empty function.


The jQuery.param() method converts an object’s key-value pairs into a query string.

For example, we can write:

const params = {
width: 1680,
height: 1050
const str = jQuery.param(params);

Then str is ‘width=1680&height=1050’ .


The jQuery.parseHTML() method lets us parse a string into an array of DOM nodes.

For example, if we have:

<div id="log">

Then we can append the parsed HTML into the div with ID log by writing:

const str = "hello, <b>my name is</b> jQuery.";
const html = $.parseHTML(str);

We parse the HTML string with $.parseHTML and then call append to append the item.


We can parse JSON string into an object with the jQuery.parseJSON() the method.

For example, if we have:

const obj = jQuery.parseJSON('{ "name": "John" }');
console.log(obj.name === "John");

Then we parse the string into the obj object.

The obj.name value is 'John' .

So the console log logs true .


The jQuery.parseXML() method lets us parse XML into an object.

For example, we can use it by writing:

const xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>",
xmlDoc = $.parseXML(xml),
$xml = $(xmlDoc),
title = $xml.find("title");

We call parseXML with the XML string.

Then we put that into the $ function so that we can call find to find the element we want.

Then we can get the text of the matched element with the text method.


The jQuery.post() method lets us make a POST request to a given URL.

For example, we can write:

const jqxhr = $.post("https://jsonplaceholder.typicode.com/posts", {
title: "title",
body: "body"
}, function() {
}, "json")
.done(function() {
console.log("second success");
.fail(function() {
.always(function() {
jqxhr.always(function() {
console.log("second finished");

to make a POST request.

The 2nd argument is the form data keys and values we want to send with the request.

The done callback is called when the request is successful.

The fail callback is called when the request failed.

always callback is called when the request is finished regardless of the result.


The jQuery.queue() method show or manipulate the queue of functions to be run on the matched element.

For example, if we have the following HTML:


and CSS:

div {
margin: 3px;
width: 40px;
height: 40px;
position: absolute;
left: 0px;
top: 30px;
background: green;
display: none;
div.newcolor {
background: blue;
span {
color: red;

Then we can animate the div by writing:

left: "+=200"
}, 2000)
left: "-=200"
}, 1500)
console.log(jQuery.queue($("div")[0], "fx"))

We get the div and use that as the argument of jQuery.queue to check the items that are queued.


We can parse JSON and XML and queue actions with jQuery.

Written by

Web developer. Subscribe to my email list now at http://jauyeung.net/subscribe/. Email me at hohanga@gmail.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store