hybrid kill3r Posted August 3, 2012 Share Posted August 3, 2012 So, I have a javascript function that when a user clicks on a link with this attached, it opens a confirmation asking if they want to continue. But instead of using onclick everytime I want to use it, I want to use something like rel="confirm" on the anchor. How would I do this? function confirmAction(hyperlink){ if(confirm(("Are you sure you want to do this? This action CANNOT be undone!!!")){ window.location = hyperlink; } else { return false; }} Link to comment Share on other sites More sharing options...
Ingolme Posted August 3, 2012 Share Posted August 3, 2012 After the page is loaded, loop through every <a> element using document.getElementsByTagName(). If the "rel" property is "confirm" then attach an event listener to the link. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now