Selecting by ID (Must know)

In this section we'll learn how to select an element by its ID and apply the same border seen previously.

How to do it...

This task can be achieved by performing the following instructions:

  1. Create a copy of the template.html file and rename it as selecting-by-id.html.
  2. Inside the <body> tag, add the following HTML markup:
    <h1 id="title">The Id selector</h1>
    <div id="container">
        This example shows you how to use the Id selector.
        <p id="description">As you can see, this time the border is applied only to the h1 element because of its id.</p>
        <span id="note">Hey, I'm a note</span>
    </div>
  3. Edit the <head> section as we did in the previous chapter, but this time add this script after the jQuery library instead:
    <script> $(document).ready(function() ...

Get Instant JQuery Selectors now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.