


Comprehensive analysis of standard attributes and custom attributes in HTML5_html5 tutorial skills
As explained in HTML5 syntax, elements can contain attributes to set various properties for an element.
Some properties are defined as global and can be used on any element, while others are defined as element-specific. All properties have a name and a value, which look like the example below.
Here is an example of using HTML5 attributes, demonstrating how to mark a div element with an attribute named class and the value "example":
Theattribute can only be specified in the opening tag and must not be used in the closing tag.
HTML5 attributes are not case-sensitive and can be used in all uppercase or a mixture of uppercase and lowercase, although the most common convention is to always use lowercase.
Standard Attributes
The attributes listed below are supported by almost all HTML5 tags.
|
Options | Function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
accesskey | User-defined | Define keyboard shortcuts for accessing elements. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
align | right, left, center | Align labels horizontally. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
background | URL | Set a background image behind the element. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bgcolor | Numerical value, hexadecimal value, RGB value | Sets a background color behind the element. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class | User defined. | Categories an element to facilitate the use of cascading style sheets. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
contenteditable | true, false | Defines whether users can edit the content of the element. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
contextmenu | Menu id | Define a context menu for the element. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
data-XXXX | User defined. | Custom attributes. Authors of HTML documents can define their own attributes. Custom properties must start with "data-". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
draggable | true,false,auto | Defines whether the user can drag the element. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
height | numeric value | Define the height of a table, image, or table cell. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
hidden | hidden | Defines whether the element should be visible. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
id | User defined. | named elements to facilitate the use of cascading style sheets. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
item | element list. | is used to combine elements. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
itemprop | List of entries. | is used to combine entries. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
spellcheck | true, false | Defines whether the element must have spelling or error checking. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
style | CSS style sheet. | defines inline styles for elements. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
subject | User-defined id. | defines the items associated with the element. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tabindex | Tab number | is determined by the tab order of the elements. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
title | User defined. | The "popup" title of theelement. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
valign | top, middle, bottom | Vertical alignment of tags within HTML elements. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
width | Numeric value. | Defines the width of tables, images and table cells. |
Custom attributes
HTML5 also introduces a new feature, which is the ability to add custom data attributes.
Custom data attributes start with data- and are named based on our needs. Here is a simple example:
...
Two of the above examples Custom attributes called data-subject and data-level are fully valid in HTML5. We can also get their values using the JavaScript API or in CSS in a similar way to standard properties.
Add custom attributes to HTML elements and access them through JavaScript. If you have tried it before, you will find that it is easy to ignore tag validation, and HTML5 can provide you with the ability to create and use your own elements within a valid web page. Attribute function.
Create HTML5 file:
If you haven’t decided which one to use yet, you can copy the code below:
- /span>
- >
- html
- >
- head
- >
- script
- >
- /*functions here*/
- script
- >
- head
- >
- body
- >
- body
- >
- html
- >
Set custom elements in the body and access them using JavaScript elements in the head script area.
Create element:
First, add some simple content and elements such as custom attributes and IDs so that we can identify the JavaScript example.
- div id="product1" data-product-category="clothing"
- >
- Cotton Shirt
- div
- >
As you can see, the custom attribute has the form: "data-*", set the name in the "data-" part or a name of your choice. Use custom attributes in HTML5, this is the only way that works. Therefore, only use this method if you want to verify whether the web page is valid.
Of course, the project details determine whether the custom property is useful to you and how you name it. This example can be applied to retail websites across different product categories.
Custom attributes allow you to use JavaScript code within the page to set elements in a special way, for example, to animate the display function. If there are no standard HTML elements, we recommend using custom attributes.
Add test button
Use your own JavaScript elements on the page to execute events, provided that the following code is added to the page:
- input type="button" value="get attribute" onclick="getElementAttribute ('product1')"
- />
Get attributes:
The most common way to access attributes in JavaScript is to use "getAttributes", which is also the first step we need to do. Add the following function in the head script area of the page:
- function getElementAttribute(elemID) {
- var theElement = document.getElementById(elemID);
- var theAttribute = theElement.getAttribute('data-product-category'); 🎜> alert(theAttribute);
- }
Here, we have added the alert value to the example. Of course, you can also add it in the script according to your own needs.
Get data:
You can use an element dataset instead of DOM "getAttributes", which may be more efficient, especially in certain cases where the code iterates through multiple attributes. However, browser support for datasets is still very low. So keeping that in mind, this code executes the same process as the method // after.
//var theAttribute = theElement.getAttribute('data-product-category');
var theAttribute = theElement.dataset.productCategory;
Remove "data-" from the attribute name in the dataset, it Still included in the HTML.
Please note that if your custom attribute name has a hyphen in it, this will appear in camel-case form when accessed via data, i.e. ("data-product-category" becomes "productCategory").
Other modules and functions
We have obtained the property, scripts can still set and remove it. The code below demonstrates how to set properties using standard JavaScript modules and datasets.
- //DOM method
- theElement.setAttribute('data-product-category', 'sale');
- //dataset version
- theElement.dataset.productCategory = "sale";
- You can also use DOM methods or data sets to delete an attribute:
- //DOM method
- theElement.removeAttribute('data-product-category');
- //dataset version
- theElement.dataset.productCategory = null;

HTML5isamajorrevisionoftheHTMLstandardthatrevolutionizeswebdevelopmentbyintroducingnewsemanticelementsandcapabilities.1)ItenhancescodereadabilityandSEOwithelementslike,,,and.2)HTML5enablesricher,interactiveexperienceswithoutplugins,allowingdirectembe

Advanced tips for H5 include: 1. Use complex graphics to draw, 2. Use WebWorkers to improve performance, 3. Enhance user experience through WebStorage, 4. Implement responsive design, 5. Use WebRTC to achieve real-time communication, 6. Perform performance optimization and best practices. These tips help developers build more dynamic, interactive and efficient web applications.

H5 (HTML5) will improve web content and design through new elements and APIs. 1) H5 enhances semantic tagging and multimedia support. 2) It introduces Canvas and SVG, enriching web design. 3) H5 works by extending HTML functionality through new tags and APIs. 4) Basic usage includes creating graphics using it, and advanced usage involves WebStorageAPI. 5) Developers need to pay attention to browser compatibility and performance optimization.

H5 brings a number of new functions and capabilities, greatly improving the interactivity and development efficiency of web pages. 1. Semantic tags such as enhance SEO. 2. Multimedia support simplifies audio and video playback through and tags. 3. Canvas drawing provides dynamic graphics drawing tools. 4. Local storage simplifies data storage through localStorage and sessionStorage. 5. The geolocation API facilitates the development of location-based services.

HTML5 brings five key improvements: 1. Semantic tags improve code clarity and SEO effects; 2. Multimedia support simplifies video and audio embedding; 3. Form enhancement simplifies verification; 4. Offline and local storage improves user experience; 5. Canvas and graphics functions enhance the visualization of web pages.

The core features of HTML5 include semantic tags, multimedia support, offline storage and local storage, and form enhancement. 1. Semantic tags such as, etc. to improve code readability and SEO effect. 2. Simplify multimedia embedding with labels. 3. Offline storage and local storage such as ApplicationCache and LocalStorage support network-free operation and data storage. 4. Form enhancement introduces new input types and verification properties to simplify processing and verification.

H5 provides a variety of new features and functions, greatly enhancing the capabilities of front-end development. 1. Multimedia support: embed media through and elements, no plug-ins are required. 2. Canvas: Use elements to dynamically render 2D graphics and animations. 3. Local storage: implement persistent data storage through localStorage and sessionStorage to improve user experience.

H5 and HTML5 are different concepts: HTML5 is a version of HTML, containing new elements and APIs; H5 is a mobile application development framework based on HTML5. HTML5 parses and renders code through the browser, while H5 applications need to run containers and interact with native code through JavaScript.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
