Jump to content

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...