Selecting by tag (Must know)

In this recipe, you'll learn how to select elements by their tag name using what is known as element selector. The goal of this task is to show you how to select and hide the paragraphs in the page.

How to do it...

To achieve our goal, perform the following the steps:

  1. Create a copy of the template.html file and rename it as selecting-by-tag-names.html.
  2. Inside the <body> tag, add the following HTML markup:
    <h1>The Tag name selector</h1>
        This example shows you how to use a tag name.
        <p>After you'll click the button below, both the paragraph of this page will be hidden.</p>
        <p>I'm yet another paragraph</p>
    <button id="hide-button">Hide elements!</button>
  3. Edit the <head> section of the page adding this code:
    <script> ...

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.