Jump to content

on click add link


manojnaanak

Recommended Posts

You can set up a link like this: <a onclick="add_child(this);"> The add_child function will take a parameter, which will be the element that you clicked on. You can use the DOM methods and properties to insert the new node after the one you clicked on. Javascript doesn't have an insertAfter method, but it has insertBefore and a nextSibling property. So your link will need to have at least one element after it (even if it's hidden and doesn't show anything), but you can do something like this:

function add_child(link){  var new_link = document.createElement('a');  new_link.innerHTML = 'new child';  link.parentNode.insertBefore(new_link, link.nextSibling);}

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...