HTML Global Attributes 2
HTML Global Attributes 2
The global attributes are attributes that can be used with all HTML elements.
Attribute Description
<html>
<body>
<ul>
<li>Edge, IE, Chrome, Safari, Opera 15+: [ALT] +
<em>accesskey</em></li>
<li>Opera prior version 15: [SHIFT] [ESC] + <em>accesskey</em></li>
<li>Firefox: [ALT] [SHIFT] + <em>accesskey</em></li>
</ul>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
h1.intro {
color: blue;
}
p.important {
color: green;
}
</style>
</head>
<body>
</body>
</html>
The class attribute specifies one or more class names for an element.
The class attribute is mostly used to point to a class in a style sheet. However, it
can also be used by a JavaScript (via the HTML DOM) to make changes to HTML
elements with a specified class.
<html>
<body>
</body>
</html>
<head>
<script>
function showDetails(animal) {
var animalType = animal.getAttribute("data-animal-type");
}
</script>
</head>
<body>
<h1>Species</h1>
<p>Click on a species to see what type it is:</p>
<ul>
</body>
</html>
The data-* attributes gives us the ability to embed custom data attributes on all
HTML elements.
The stored (custom) data can then be used in the page's JavaScript to create a
more engaging user experience (without any Ajax calls or server-side database
queries).
1. The attribute name should not contain any uppercase letters, and must be at
least one character long after the prefix "data-"
2. The attribute value can be any string
HTML dir Attribute
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<html>
<head>
<style>
#div1 {
width: 350px;
height: 70px;
padding: 10px;
</style>
<script>
function allowDrop(ev) {
ev.preventDefault();
function drag(ev) {
ev.dataTransfer.setData("Text", ev.target.id);
function drop(ev) {
var data = ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
ev.preventDefault();
</script>
</head>
<body>
<br>
</body>
</html>
Common examples are "en" for English, "es" for Spanish, "fr" for French, and so
on.
<!DOCTYPE html>
<html>
<body>
<p>This is a paragraph.</p>
</body>
</html>
<html>
<body>
</body>
</html>