PDA

View Full Version : Urgent - problem with browsers while parsing innerHTML



ak_jsohi4u
05-09-2006, 03:40 PM
Hii,

I am trying to parse the innerHTML like this...

//InnerHTML = "<INPUT id=TreeViewPR1_TreeView1n14CheckBox title=Hostage type=checkbox CHECKED name=TreeViewPR1_TreeView1n14CheckBox>
//<SPAN class=\"TreeViewPR1_TreeView1_0 TreeViewPR1_TreeView1_1\" id=TreeViewPR1_TreeView1t14 title='Extract This string'>Hostage</SPAN>"

function AddNodeid(InnerHTML)
{

var TitleIndex=InnerHTML.lastIndexOf("title=");

if (TitleIndex > 0)
{
var SubString= InnerHTML.substring(TitleIndex+6, InnerHTML.length+1);


var EndIndex=SubString.indexOf("id="); // For Firefox

if(EndIndex <=0)
EndIndex=SubString.indexOf(">"); // For IE

var Nodeid=SubString.substring(0, EndIndex);

alert(Nodeid);
}
else
alert("No NodeId");
}


the problems are becoz of browsers..

Firefox interchanges the positions of title and id in <SPAN> tag...

and another prob with this code is that IE returns id without quotes( i.e 01) but FF returnsin double quotes(i.e "01").

can you tell why this happens and is there a way by which I can directly get
title, value pair.:confused:

Thanks in advance..

Cheerio
Abhishek

Kor
05-09-2006, 04:13 PM
innerHTML is not a standard DOM method, thus it can not insert the new elements into the DOM page's tree. use DOM methods to append new elements.

ak_jsohi4u
05-09-2006, 04:24 PM
innerHTML is not a standard DOM method, thus it can not insert the new elements into the DOM page's tree. use DOM methods to append new elements.
Hi Kor,

Thanks for replying,
Actually I am not trying to insert anything , ijust want to parse this string(innerHTML) and retrieve the value of 'title' of <SPAN> tag(i.e "Extract this Text"), this funct is working but there are some prob with firefox...

Hope I am more clear now...

Cheerio
Abhishek

jscheuer1
05-09-2006, 06:18 PM
alert(document.getElementById('TreeViewPR1_TreeView1t14').title)

jscheuer1
05-10-2006, 06:06 AM
BTW, I should add that I saw no discrepancy when I tried out your example, which needed a bit of editing to do anything so, may have lost something in the translation (both IE and FF used the same branch:


if(EndIndex <=0)
EndIndex=SubString.indexOf(">"); // For IE

and returned the same result). Also, InnerHTML is simply a variable, while innerHTML is an object of HTML elements. Finally, I should have included with my above post, a question like, "Why can't you just query the title attribute directly as illustrated?"

ak_jsohi4u
05-10-2006, 06:09 AM
alert(document.getElementById('TreeViewPR1_TreeView1t14').title)
Hii john,

Thanks for the idea, its great, I came to do all this in one line after little modification...

Cheerio
Abhishek

ak_jsohi4u
05-10-2006, 07:13 AM
BTW, I should add that I saw no discrepancy when I tried out your example, which needed a bit of editing to do anything so, may have lost something in the translation (both IE and FF used the same branch:


if(EndIndex <=0)
EndIndex=SubString.indexOf(">"); // For IE

and returned the same result). Also, InnerHTML is simply a variable, while innerHTML is an object of HTML elements. Finally, I should have included with my above post, a question like, "Why can't you just query the title attribute directly as illustrated?"
Hi John,

Sorry for not telling this before, actually i am accessing innerHTML like this
for a treeview control of asp.net..

AddNodeid(event.srcElement.parentNode.innerHTML);

FF and IE return different results(just interchange the position of title and id i.e. <SPAN ... title='Extract This string' , id=TreeViewPR1_TreeView1t14 >Hostage</SPAN>"),

But we can access title directly by-

event.srcElement.nextSibling.title

come to know this after your reply

Can you tell any link about differences in tag's supported by IE and FF...

Thanks for your help...

Cheerio
Abhishek