Created
April 26, 2011 15:09
-
-
Save jnbek/942452 to your computer and use it in GitHub Desktop.
Insert After for use with Uploads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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