Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Urgent - problem with browsers while parsing innerHTML

    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.

    Thanks in advance..

    Cheerio
    Abhishek

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kor
    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

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    alert(document.getElementById('TreeViewPR1_TreeView1t14').title)
    - John

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    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?"
    - John

  • #6
    New to the CF scene
    Join Date
    May 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jscheuer1
    Code:
    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

  • #7
    New to the CF scene
    Join Date
    May 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jscheuer1
    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:

    Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •