> For the complete documentation index, see [llms.txt](https://docs.webmix.cc/jquery/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.webmix.cc/jquery/3.-xuan-ze-zi-selectors/3.1-name-he-id-he-class.md).

# 3.1 name 和 id 和 class

## 標籤名稱

**`$("p")`**：找到標籤名稱為 p 的元素。

**`$("h1")`**：找到標籤名稱為 h1 的元素。

## id

**`$("#my_id")`**：**#** 表示的是 id，即找到 id 為 my\_id 的元素。

**`$("h1#my_title")`**：找到 h1 標籤，且 id 為 my\_title 的元素。

## class

**`$(".my_style")`**：**.** 表示的是 class，即找到 class 為 my\_style 的元素。

**`$("p.my_style")`**：找到 p 標籤，且 class 為 my\_style 的元素。

## 練習

請先建立 `practice/selectors.html` 檔案，用於練習，內容如下：

```markup
<!doctype html>
<html lang="zh-Hant">
  <head>
    <meta charset="utf-8">
    <title>jQuery 相關練習</title>
  </head>
  <body>
    <h1>這是標題</h1>
    <h1 id="my_title">這是我的標題</h1>
    <p>這是段落1</p>
    <p class="para para2">這是段落2</p>
    <p class="para para3">段是段落3</p>

    <script src="./vendors/jquery/jquery-3.4.1.min.js"></script>
    <script>
      // 程式碼在這輸入...
    </script>
  </body>
</html>
```

試著輸入以下例子，看是否有效：

```javascript
$("h1").css("color", "red");
```

```javascript
$("p").css("color", "red");
```

```javascript
$("h1#my_title").css("color", "red");
```

```javascript
$(".para").css("color", "red");
```

```javascript
$(".para2").css("color", "red");
```

```javascript
$("p.para3").css("color", "red");
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.webmix.cc/jquery/3.-xuan-ze-zi-selectors/3.1-name-he-id-he-class.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
