I am trying to make this code: <div data-alert="abc@abc.com">Connect me(click me to know my email)</div>
<script> var dataalert = /*access the "data-alert" here*/;window.alert("dataalert");
, but I don't know how to access it with my javascript.
Asked
Active
Viewed 117 times
-1

Lava Snake King
- 3
- 2
1 Answers
0
First, get the div using the tag selector and then use getAttribute
method of js to get the value of data-alert
attribute.
console.log(document.getElementsByTagName("div")[0].getAttribute("data-alert"))
<div data-alert="abc@abc.com">Connect me(click me to know my email)</div>

Yash Maheshwari
- 1,842
- 2
- 7
- 16
-
but i have other div – Lava Snake King Jun 07 '21 at 10:11
-
I didn't understand what you are telling. – Yash Maheshwari Jun 07 '21 at 10:24