Skip to content

Instantly share code, notes, and snippets.

@jnbek
Created April 26, 2011 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnbek/942452 to your computer and use it in GitHub Desktop.
Save jnbek/942452 to your computer and use it in GitHub Desktop.
Insert After for use with Uploads
function insertAfter(newElement,targetElement) {
//target is what you want it to go after. Look for this elements parent.
var parent = targetElement.parentNode;
//if the parents lastchild is the targetElement...
if(parent.lastchild == targetElement) {
//add the newElement after the target element.
parent.appendChild(newElement);
} else {
// else the target has siblings, insert the new element between the target and it's next sibling.
parent.insertBefore(newElement, targetElement.nextSibling);
}
}
function show_attachments()
{
if (document.attachment) document.attatchment.abort();
document.attachment = ajax_get({
url: the_url,
handler: function (req, args) {
var json_resp = eval("("+req.responseText+")");
attachment_result = json_resp.attachment_result;
attachment_link = json_resp.attachment_link
attachment_filename = json_resp.attachment_filename;
attach_div = document.getElementById('attach_div');
if(attach_div)
{
newDiv = document.createElement("div");
newDiv.innerHTML = "<a target='_blank' href='"+attachment_link+"'>"+attachment_filename+"</a>";
my parent_div = document.getElementById("attachment");
document.body.insertAfter(newDiv, parent_div);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment