Created
December 20, 2010 09:34
-
-
Save dallarosa/748200 to your computer and use it in GitHub Desktop.
Function for inserting some content (thread) after a marker(needle) inside a container (haystack). haystack should be and object.
This file contains hidden or 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 insert_after(haystack, needle, thread) | |
{ | |
var browser=navigator.userAgent; | |
if((typeof haystack.innerText == 'undefined') || (!(browser.indexOf("MSIE")>0))) | |
{ | |
var haystackText = haystack.innerHTML; | |
} | |
else | |
{ | |
var haystackText = haystack.innerText; | |
} | |
var index=haystackText.indexOf(needle); | |
var bgnText = haystackText.substr(0,index+needle.length+1); | |
var endText = haystackText.substr(index+needle.length,haystackText.length); | |
if((typeof haystack.innerText == 'undefined') || (!(browser.indexOf("MSIE")>0))) | |
{ | |
haystack.innerHTML = bgnText + thread + endText; | |
} | |
else | |
{ | |
haystack.innerText = bgnText + thread + endText; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function works (tested) with IE8, FF3.6, Safari 5, Chrome 8 on Linux and Windows.