DEV Community

AakritiGoyal12458
AakritiGoyal12458

Posted on

4 2

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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

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 . 😁

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay