-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobal-Attributes.js
72 lines (50 loc) · 1.77 KB
/
Global-Attributes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//* Global Attributes - JavaScript
/* In Html, there are global attributes that can be used on almost all elements. These attributes They
are part of the common set of attributes that can be applied to most Html elements. Some of the most
common global attributes are: */
//? 1. `id`:
// The `id` attribute provides a unique identifier for an element.
//* Html
/*
<div id="myDiv">Content</div>
*/
let myDiv = document.getElementById("myDiv");
//? 2. `class`:
// The `class` attribute is used to apply one or more classes to an element.
//* Html
/*
<p class="featuredparagraph">This is a featured paragraph.</p>
*/
//? 3. `style`:
// The `style` attribute is used to apply styles directly to the element.
//* Html
/*
<div style="color: red; font-size: 16px;">Text in red and font size of 16px.</div>
*/
//? 4. `title`:
/* The `title` attribute is used to provide additional information about an element when the
mouse is placed over it. */
//* Html
/*
<a href="#" title="Example link">Link</a>
*/
//* 5. `lang`:
// The `lang` attribute is used to specify the primary language of the element's content.
//* Html
/*
<html lang="en">
<!-- Page content -->
</html>
*/
//* 6. `data-*`:
/* The `data-*` attributes are used to store private custom information for use by
scripts. */
//* Html
/*
<div data-info="personalizedinformation">Content</div>
*/
let custominfo = document.querySelector("[data-info]").dataset.info;
/* These are just some examples of global attributes. You can use these attributes in various
Html elements to add functionality and style to your web pages. When you work with JavaScript,
You can access and manipulate these attributes using the Dom to create dynamic interactivity
in your Web page. */