-1

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.

1 Answers1

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