I have a script that processes the innerHTML from a div on a page. The innerHTML contains <BR> tags. Basically I need to remove certain substrings from the innerHTML of the div and also its cooresponding <BR>. I am using some exist js for the removal and with the modifications I have made it works and also cleans up the tailing <BR> in Firefox, but not in IE7. Here is an example.
after the script removes "horse" it looks like this.
Now I need to remove one of the <BR> tags where it is <BR><BR>. So I do this.
This works fine in Firefox, meaning it finds the index correctly for retIdx above. However, in IE it returns a -1, never finds it.
I tried the suggestion from this site for indexOf, but still no luck.
Any suggestions on how to get around this? I know I could probably take a whole different approach, but I am looking for a way to make this way work. Or, if there is just no way for it to work this way, let me know. Basically it comes to it has to work in IE and Firefox.
Thanks in advance for the help and advice.
Troy
Code:
innerHTML = dog<BR>cat<BR>horse<BR>bear<BR>
after the script removes "horse" it looks like this.
Code:
innerHTML = dog<BR>cat<BR><BR>bear<BR>
Now I need to remove one of the <BR> tags where it is <BR><BR>. So I do this.
Code:
var newTxtStr = myDiv.innerHTML;
var retIdx = newTxtStr.indexOf("<br><br>");
if(retIdx != 0 && retIdx != -1)
{
newTxtStr= newTxtStr.substring(0, retIdx) + newTxtStr.substring(retIdx+4, newTxtStr.length);
}
This works fine in Firefox, meaning it finds the index correctly for retIdx above. However, in IE it returns a -1, never finds it.
I tried the suggestion from this site for indexOf, but still no luck.
Any suggestions on how to get around this? I know I could probably take a whole different approach, but I am looking for a way to make this way work. Or, if there is just no way for it to work this way, let me know. Basically it comes to it has to work in IE and Firefox.
Thanks in advance for the help and advice.
Troy