title: Put the knife down and take a green herb, dude. |
descrip: One feller's views on the state of everyday computer science & its application (and now, OTHER STUFF) who isn't rich enough to shell out for www.myfreakinfirst-andlast-name.com Using 89% of the same design the blog had in 2001. |
FOR ENTERTAINMENT PURPOSES ONLY!!!
Back-up your data and, when you bike, always wear white. As an Amazon Associate, I earn from qualifying purchases. Affiliate links in green. |
|
Tuesday, November 03, 2015 | |
document.body.insertBefore( document.createElement("test1"), document.body.childNodes[0] ); That could've been easier. I think. Bottom line is that you're taking the parent node, and inserting a new node (first parameter) before the existing (second param). Here, of course, I'm doing it to the body. Sub document.body with the node o' your choice. EDIT: So here's a slightly nicer way of inserting html, since the above won't actually parse HTML in the string... function insertAsFirstChild(strHtml, nodeWithChildren) { // If strHtml isn't wrapped in tags, we probably want to put into // a span so that we can accept html. CreateTextElement would push // out the text as is, showing markup in the page. var newSpan, strTag, strEndTag; newSpan = document.createElement("span"); if (!nodeWithChildren) { nodeWithChildren = document.body; } if ( 0 === strHtml.indexOf("<") && strHtml.length - 1 === strHtml.lastIndexOf(">") && strHtml.indexOf("</" > -1) ) { strTag = strHtml.substring(1, strHtml.indexOf(">")); strEndTag = strHtml.slice(strHtml.lastIndexOf("</")+2, -1); if (strTag && strTag === strEndTag) { newSpan = document.createElement(strTag); strHtml = strHtml.substring(strHtml.indexOf(">")+1, strHtml.lastIndexOf("</")); } } newSpan.innerHTML = strHtml; nodeWithChildren.insertBefore(newSpan, nodeWithChildren.childNodes[0]); } Labels: javascript, noteToSelf posted by ruffin at 11/03/2015 10:46:00 AM |
|
| |
MarkUpDown is the best Markdown editor for professionals on Windows 10. It includes two-pane live preview, in-app uploads to imgur for image hosting, and MultiMarkdown table support. Features you won't find anywhere else include...
You've wasted more than $15 of your time looking for a great Markdown editor. Stop looking. MarkUpDown is the app you're looking for. Learn more or head over to the 'Store now! |
![]() |
|
|