HTML Id

作者: 春暖花开奇奇乐乐 | 来源:发表于2018-11-16 15:36 被阅读14次

Using The id Attribute

The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).

The id value can be used by CSS and JavaScript to perform certain tasks for a unique element with the specified id value.

In CSS, to select an element with a specific id, write a hash (#) character, followed by the id of the element:

Tip: The id attribute can be used on any HTML element.

Note: The id value is case-sensitive.

Note: The id value must contain at least one character, and must not contain whitespace (spaces, tabs, etc.).

1. Difference Between Class and ID

An HTML element can only have one unique id that belongs to that single element, while a class name can be used by multiple elements:


2. Bookmarks with ID and Links

HTML bookmarks are used to allow readers to jump to specific parts of a Web page.

Bookmarks can be useful if your webpage is very long.

To make a bookmark, you must first create the bookmark, and then add a link to it.

When the link is clicked, the page will scroll to the location with the bookmark.

3. Using The id Attribute in JavaScript

JavaScript can access an element with a specified id by using the getElementById() method:

相关文章

  • HTML Id

    Using The id Attribute Theidattribute specifies a unique ...

  • HTML的id和name

    id 定义:id 属性规定 HTML 元素的唯一的 id。 用途: 用途1:id是HTML元素的Identity,...

  • CSS 选择器

    1、id 选择器 id 选择器可以为标有特定 id 的 HTML 元素指定特定的样式。HTML元素以id属性来设置...

  • html中name和id区别

    关于id 1.id 属性规定 HTML 元素的唯一的 id。 2.id 在 HTML 文档中必须是唯一的。 3.i...

  • html的属性id和name

    属性id id 属性规定 HTML 元素的唯一的 id。id 在 HTML 文档中必须是唯一的。 根据提供的唯一i...

  • JS中一个按钮,点击选中,在此点击取消选中

    Html: Js:var flag = true;function chkRadio(id) {id.checke...

  • HTML DOM 笔记

    通过id查找HTML 元素var element = document.getElementById('ID') ...

  • js基础

    修改html的内容 document.getElementById(id).innerHTML=new HTML ...

  • 2018-12-07

    HTML 树 id name pid 提交 cssbody{ba...

  • 品牌列表

    品牌列表 添加品牌 ID: 品牌名称: ID 品牌...

网友评论

      本文标题:HTML Id

      本文链接:https://www.haomeiwen.com/subject/snymfqtx.html