In the last exercise, you used jQuery to cut twelve lines of code down to three.
Let’s use LEGO bricks as an analogy for understanding how jQuery works. With an infinite number of bricks, you could build an entire city — of course, this would take a long time. What if you were given pre-made LEGO buildings, LEGO roads, LEGO parks, etc? You could build a city much faster.
The JavaScript language represents an infinite supply of LEGO bricks — the possibilities are endless but time-consuming. The pre-made LEGO structures are like jQuery methods. You can use these methods to add dynamic behavior, such as .hide()
, .show()
, .fadeIn()
, .fadeOut()
etc., to HTML elements.
The example in the last exercise took twelve lines of JavaScript, but was achieved with only three lines of jQuery’s .click()
and .toggle()
methods.
Instructions
In the next exercise, we’ll show you how to load the jQuery library into your app so that you can make use of these powerful, pre-made methods.