Member-only story

jQuery — Deferred and Data

John Au-Yeung
3 min readDec 30, 2020

--

Photo by Johann Siemens 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.

.data()

We can store data within matched elements with the data method.

For example, we can write the following HTML:

<span></span>

Then use data to store and get the data as follows:

$("body").data("foo", 52);
$("span").first().text($("body").data("foo"));

We save the data with key 'foo' and value 52 in the first line.

Then in the 2nd line, we get the data and put it in the span .

.dblclick()

The .dblclick() method binds an event handler to the dblclick event or trigger the event on an element.

For example, if we have the following HTML:

<div id="target">
Double-click here
</div>
<div id="other">
Trigger the handler
</div>

Then we can listen to double clicks on the div with ID target by writing:

$("#target").dblclick(function() {
alert("Handler for .dblclick() called.");
});

We can also trigger a double click on the div with ID target when we click on the div with ID…

--

--

No responses yet