-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
30 lines (25 loc) · 971 Bytes
/
test.html
File metadata and controls
30 lines (25 loc) · 971 Bytes
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Find HTML Tags with Attribute</title>
</head>
<body>
<!-- Example HTML with data-text attribute -->
<div data-text="example">This is a div with data-text attribute.</div>
<p data-text="paragraph">This is a paragraph with data-text attribute.</p>
<span>This element does not have data-text attribute.</span>
<script>
// Function to find HTML tags with a specific attribute
function findElementsWithAttribute(attributeName) {
const elementsWithAttribute = document.querySelectorAll(`[${attributeName}]`);
return Array.from(elementsWithAttribute);
}
// Find elements with data-text attribute
const elementsWithDataText = findElementsWithAttribute('data-text');
// Log the found elements to the console
console.log('Elements with data-text attribute:', elementsWithDataText);
</script>
</body>
</html>