DEV Community

AakritiGoyal12458
AakritiGoyal12458

Posted on

Creating HTML <a> Anchor </a> Tag With JAVASCRIPT

This article will help you to create link over any text you have used in your webpage without using anchor tags of html .

Also whenever you will click on link it will ask you to confirm whether you want to continue or not ...

continue or not

Step 1

We know Browser know our current workspace and JavaScript is the best way to communicate with browser . So with this command
document.location="delete_me.html" JavaScript can ask for your current location from Browser .

Step 2

We have confirm dialog box in JS confirm()which gives its o/p as Boolean values . These values can be used with if and else conditions .

Code:

<script>
function abc(){

var c= confirm("Do you want to Continue....?? ");

if(c)
     {
          document.location="delete_me.html";
     }
else
     {
          alert("we stay here");
     }

}
</script>

<body>
<div onclick=abc()>Click me </div> 
</body>
Enter fullscreen mode Exit fullscreen mode

Thank You

Top comments (2)

Collapse
 
alidarrudi profile image
ali

very simple...

Collapse
 
aakritigoyal12458 profile image
AakritiGoyal12458

Thank you for your valuable suggestion . And I Have recently started my JavaScript journey and so I got to learnt a lot from your feedback . šŸ˜