IE, dom access in a HTMLDocument ?!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • marc

    IE, dom access in a HTMLDocument ?!

    I think, it's very simple to do, but i don't know how ?!
    i've got a html page which contains :

    <div id="myDiv">
    <hr />
    <hr />
    <hr />
    <hr />
    </div>

    And in a javascript (client side), i want to access to the dom model of the
    div :
    i wan't to be able to use selectnodes on "myDiv" :
    be able to do something like that :

    var myDiv = document.GetEle mentById("myDiv ");
    var xmlDoc = myDiv.implement ation ; // to obtain dom of mydiv ?!
    var nodeList = xmlDoc.selectNo des("hr") ;

    is it possible with "microsoft internet explorer" ? (it works on gecko based
    browsers)


  • mscir

    #2
    Re: IE, dom access in a HTMLDocument ?!

    marc wrote:[color=blue]
    > I think, it's very simple to do, but i don't know how ?!
    > i've got a html page which contains :
    > <div id="myDiv">
    > <hr />
    > <hr />
    > <hr />
    > <hr />
    > </div>
    > And in a javascript (client side), i want to access to the dom model of the
    > div :
    > i wan't to be able to use selectnodes on "myDiv" :
    > be able to do something like that :
    >
    > var myDiv = document.GetEle mentById("myDiv ");
    > var xmlDoc = myDiv.implement ation ; // to obtain dom of mydiv ?!
    > var nodeList = xmlDoc.selectNo des("hr") ;
    >
    > is it possible with "microsoft internet explorer" ?[/color]

    Gain technical skills through documentation and training, earn certifications and connect with the community

    Gain technical skills through documentation and training, earn certifications and connect with the community


    function remove() {
    var target=document .getElementById ('myDiv');
    target.removeCh ild(target.chil dNodes[0]);
    }
    function add(){
    var target=document .getElementById ('myDiv');
    var oHR=document.cr eateElement("HR ");
    target.appendCh ild(oHR);
    }

    <div id="myDiv">
    <hr>
    <hr>
    <hr>
    <hr>
    </div>

    <input type="button" value="Remove Child Nodes" onclick="remove ()">
    <input type="button" value="Add Child Nodes" onclick="add()" >

    MIke

    Comment

    • marc

      #3
      Re: IE, dom access in a HTMLDocument ?!

      "mscir" <mscir@access4l ess.com.net.org .uk> a écrit dans le message de news:
      1094815i8ibpf52 @corp.supernews .com...[color=blue]
      > marc wrote:[color=green]
      > > I think, it's very simple to do, but i don't know how ?!
      > > i've got a html page which contains :
      > > <div id="myDiv">
      > > <hr />
      > > <hr />
      > > <hr />
      > > <hr />
      > > </div>
      > > And in a javascript (client side), i want to access to the dom model of[/color][/color]
      the[color=blue][color=green]
      > > div :
      > > i wan't to be able to use selectnodes on "myDiv" :
      > > be able to do something like that :
      > >
      > > var myDiv = document.GetEle mentById("myDiv ");
      > > var xmlDoc = myDiv.implement ation ; // to obtain dom of mydiv ?!
      > > var nodeList = xmlDoc.selectNo des("hr") ;
      > >
      > > is it possible with "microsoft internet explorer" ?[/color]
      >
      >[/color]
      Gain technical skills through documentation and training, earn certifications and connect with the community

      d.asp[color=blue]
      >[/color]
      Gain technical skills through documentation and training, earn certifications and connect with the community

      d.asp[color=blue]
      >
      > function remove() {
      > var target=document .getElementById ('myDiv');
      > target.removeCh ild(target.chil dNodes[0]);
      > }
      > function add(){
      > var target=document .getElementById ('myDiv');
      > var oHR=document.cr eateElement("HR ");
      > target.appendCh ild(oHR);
      > }
      >
      > <div id="myDiv">
      > <hr>
      > <hr>
      > <hr>
      > <hr>
      > </div>
      >
      > <input type="button" value="Remove Child Nodes" onclick="remove ()">
      > <input type="button" value="Add Child Nodes" onclick="add()" >
      >
      > MIke[/color]

      i don't want to be able to add ou remove childs ...
      i want to be able to get a list of nodes ...
      i'd like to write : document.select Nodes("/hr"); ...
      but IE doesn't like that ?!?


      Comment

      • Csaba Gabor

        #4
        Re: IE, dom access in a HTMLDocument ?!

        // note capitalization difference
        var myDiv = document.getEle mentById("myDiv ");
        var myNodes = myDiv.getElemen tsByTagName('HR ');

        Csaba Gabor

        "marc" <Marc.LENTZ@ctr ceal.caisse-epargne.fr> wrote in message
        news:c6svg0$2ps $1@s1.read.news .oleane.net...[color=blue]
        > I think, it's very simple to do, but i don't know how ?!
        > i've got a html page which contains :
        >
        > <div id="myDiv">
        > <hr />
        > <hr />
        > <hr />
        > <hr />
        > </div>
        >
        > And in a javascript (client side), i want to access to the dom model of[/color]
        the[color=blue]
        > div :
        > i wan't to be able to use selectnodes on "myDiv" :
        > be able to do something like that :
        >
        > var myDiv = document.GetEle mentById("myDiv ");
        > var xmlDoc = myDiv.implement ation ; // to obtain dom of mydiv ?!
        > var nodeList = xmlDoc.selectNo des("hr") ;
        >
        > is it possible with "microsoft internet explorer" ? (it works on gecko[/color]
        based[color=blue]
        > browsers)
        >
        >[/color]


        Comment

        • Grant Wagner

          #5
          Re: IE, dom access in a HTMLDocument ?!

          marc wrote:
          [color=blue]
          > "mscir" <mscir@access4l ess.com.net.org .uk> a écrit dans le message de news:
          > 1094815i8ibpf52 @corp.supernews .com...[color=green]
          > > marc wrote:[color=darkred]
          > > > I think, it's very simple to do, but i don't know how ?!
          > > > i've got a html page which contains :
          > > > <div id="myDiv">
          > > > <hr />
          > > > <hr />
          > > > <hr />
          > > > <hr />
          > > > </div>
          > > > And in a javascript (client side), i want to access to the dom model of[/color][/color]
          > the[color=green][color=darkred]
          > > > div :
          > > > i wan't to be able to use selectnodes on "myDiv" :
          > > > be able to do something like that :
          > > >
          > > > var myDiv = document.GetEle mentById("myDiv ");
          > > > var xmlDoc = myDiv.implement ation ; // to obtain dom of mydiv ?!
          > > > var nodeList = xmlDoc.selectNo des("hr") ;
          > > >
          > > > is it possible with "microsoft internet explorer" ?[/color]
          > >
          > >[/color]
          > http://msdn.microsoft.com/workshop/a...ods/appendchil
          > d.asp[color=green]
          > >[/color]
          > http://msdn.microsoft.com/workshop/a...ods/removechil
          > d.asp[color=green]
          > >
          > > function remove() {
          > > var target=document .getElementById ('myDiv');
          > > target.removeCh ild(target.chil dNodes[0]);
          > > }
          > > function add(){
          > > var target=document .getElementById ('myDiv');
          > > var oHR=document.cr eateElement("HR ");
          > > target.appendCh ild(oHR);
          > > }
          > >
          > > <div id="myDiv">
          > > <hr>
          > > <hr>
          > > <hr>
          > > <hr>
          > > </div>
          > >
          > > <input type="button" value="Remove Child Nodes" onclick="remove ()">
          > > <input type="button" value="Add Child Nodes" onclick="add()" >
          > >
          > > MIke[/color]
          >
          > i don't want to be able to add ou remove childs ...
          > i want to be able to get a list of nodes ...
          > i'd like to write : document.select Nodes("/hr"); ...
          > but IE doesn't like that ?!?[/color]

          <body onload="a();">
          <div id="myDiv"> <hr> <hr> <hr> <hr> </div>
          <script>
          function a() {
          var output = [];
          if (document.getEl ementById) {
          var div = document.getEle mentById('myDiv ');
          if (div && div.getElements ByTagName) {
          var divHRs = div.getElements ByTagName('hr') ;
          if (divHRs) {
          for (var i = 0; i < divHRs.length; i++) {
          output.push(div HRs[i].nodeName);
          }
          }
          }
          }
          alert(output.jo in('\n'));
          }
          </script>

          Works in Gecko based browsers (Netscape 7, Mozilla, Firefox, Camino), IE and
          Opera 7.

          If you want all the children of "myDiv", you can use the div.childNodes[]
          collection instead of retrieving only the HRs with getElementsByTa gName().

          --
          | Grant Wagner <gwagner@agrico reunited.com>

          * Client-side Javascript and Netscape 4 DOM Reference available at:
          *


          * Internet Explorer DOM Reference available at:
          *
          Gain technical skills through documentation and training, earn certifications and connect with the community


          * Netscape 6/7 DOM Reference available at:
          * http://www.mozilla.org/docs/dom/domref/
          * Tips for upgrading JavaScript for Netscape 7 / Mozilla
          * http://www.mozilla.org/docs/web-deve...upgrade_2.html


          Comment

          • sharon

            #6
            Re: IE, dom access in a HTMLDocument ?!

            you can get the list of the HR tags inside myDiv using the
            getElementsByTa gName:

            var myDiv = document.getEle mentById("myDiv ");
            var nodeList = myDiv.getElemen tsByTagName("HR ");

            Please note that Internet Explorer does not have native support in XML
            (you have to use activeX to work with XML)

            "marc" <Marc.LENTZ@ctr ceal.caisse-epargne.fr> wrote in message news:<c6svg0$2p s$1@s1.read.new s.oleane.net>.. .[color=blue]
            > I think, it's very simple to do, but i don't know how ?!
            > i've got a html page which contains :
            >
            > <div id="myDiv">
            > <hr />
            > <hr />
            > <hr />
            > <hr />
            > </div>
            >
            > And in a javascript (client side), i want to access to the dom model of the
            > div :
            > i wan't to be able to use selectnodes on "myDiv" :
            > be able to do something like that :
            >
            > var myDiv = document.GetEle mentById("myDiv ");
            > var xmlDoc = myDiv.implement ation ; // to obtain dom of mydiv ?!
            > var nodeList = xmlDoc.selectNo des("hr") ;
            >
            > is it possible with "microsoft internet explorer" ? (it works on gecko based
            > browsers)[/color]

            Comment

            • marc

              #7
              Re: IE, dom access in a HTMLDocument ?!

              thanx a lot for all your answers ...

              i note that IE can't do a xpath evaluation in the dom of the html
              i wouldn't know how IE is developped ... but i'm pretty sure that is an
              amount of craps, patch ...

              i've made a script, for my firefox browsers, full of "selectNodes"(e valuate)
              in a html document...
              and if i wanna port it to IE, i should replace all xpath expressions by some
              getelementstagb yname ;-(


              "sharon" <sharon@athoc.c om> a écrit dans le message de news:
              8425d061.040430 0802.2b390fc7@p osting.google.c om...[color=blue]
              > you can get the list of the HR tags inside myDiv using the
              > getElementsByTa gName:
              >
              > var myDiv = document.getEle mentById("myDiv ");
              > var nodeList = myDiv.getElemen tsByTagName("HR ");
              >
              > Please note that Internet Explorer does not have native support in XML
              > (you have to use activeX to work with XML)
              >
              > "marc" <Marc.LENTZ@ctr ceal.caisse-epargne.fr> wrote in message[/color]
              news:<c6svg0$2p s$1@s1.read.new s.oleane.net>.. .[color=blue][color=green]
              > > I think, it's very simple to do, but i don't know how ?!
              > > i've got a html page which contains :
              > >
              > > <div id="myDiv">
              > > <hr />
              > > <hr />
              > > <hr />
              > > <hr />
              > > </div>
              > >
              > > And in a javascript (client side), i want to access to the dom model of[/color][/color]
              the[color=blue][color=green]
              > > div :
              > > i wan't to be able to use selectnodes on "myDiv" :
              > > be able to do something like that :
              > >
              > > var myDiv = document.GetEle mentById("myDiv ");
              > > var xmlDoc = myDiv.implement ation ; // to obtain dom of mydiv ?!
              > > var nodeList = xmlDoc.selectNo des("hr") ;
              > >
              > > is it possible with "microsoft internet explorer" ? (it works on gecko[/color][/color]
              based[color=blue][color=green]
              > > browsers)[/color][/color]


              Comment

              • Dr John Stockton

                #8
                Re: IE, dom access in a HTMLDocument ?!

                JRS: In article <dLadnQ2TAtgoAz fd4p2dnA@comcas t.com>, seen in
                news:comp.lang. javascript, Randy Webb <hikksnotathome @aol.com> posted at
                Tue, 18 May 2004 19:39:02 :
                [color=blue]
                > The FAQ has a section that explains how to emulate
                >getElementBy Id in IE4, and to date, there have been no posts about it
                >failing.
                >[/color]

                It's not clear to me which section you are referring to.

                4.41, 4.26, 4.15 contain the only references to getElementbyID, and none
                of those generate it.

                I daren't suppose that you have mis-remembered <URL:http://www.merlyn.
                demon.co.uk/js-other.htm#OD> , or similar, as being part of the FAQ !

                --
                © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
                <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                Comment

                • Randy Webb

                  #9
                  Re: IE, dom access in a HTMLDocument ?!

                  Dr John Stockton wrote:
                  [color=blue]
                  > JRS: In article <dLadnQ2TAtgoAz fd4p2dnA@comcas t.com>, seen in
                  > news:comp.lang. javascript, Randy Webb <hikksnotathome @aol.com> posted at
                  > Tue, 18 May 2004 19:39:02 :
                  >
                  >[color=green]
                  >>The FAQ has a section that explains how to emulate
                  >>getElementByI d in IE4, and to date, there have been no posts about it
                  >>failing.
                  >>[/color]
                  >
                  >
                  > It's not clear to me which section you are referring to.
                  >
                  > 4.41, 4.26, 4.15 contain the only references to getElementbyID, and none
                  > of those generate it.[/color]



                  Leads to:



                  But you are correct, its not in the FAQ formal. For some reason, I
                  thought it was added in the 4.15 but it is in the notes for that section.

                  But, for curiosity sake, does it break anywhere in your IE4?

                  --
                  Randy
                  Chance Favors The Prepared Mind
                  comp.lang.javas cript FAQ - http://jibbering.com/faq/

                  Comment

                  • Dr John Stockton

                    #10
                    Re: IE, dom access in a HTMLDocument ?!

                    JRS: In article <R_OdnatqoOGhJj bdRVn-iQ@comcast.com> , seen in
                    news:comp.lang. javascript, Randy Webb <hikksnotathome @aol.com> posted at
                    Wed, 19 May 2004 15:53:08 :[color=blue]
                    >Dr John Stockton wrote:
                    >[color=green]
                    >> JRS: In article <dLadnQ2TAtgoAz fd4p2dnA@comcas t.com>, seen in
                    >> news:comp.lang. javascript, Randy Webb <hikksnotathome @aol.com> posted at
                    >> Tue, 18 May 2004 19:39:02 :
                    >>
                    >>[color=darkred]
                    >>>The FAQ has a section that explains how to emulate
                    >>>getElementBy Id in IE4, and to date, there have been no posts about it
                    >>>failing.
                    >>>[/color]
                    >>
                    >>
                    >> It's not clear to me which section you are referring to.
                    >>
                    >> 4.41, 4.26, 4.15 contain the only references to getElementbyID, and none
                    >> of those generate it.[/color]
                    >
                    >http://www.jibbering.com/faq/#FAQ4_15
                    >
                    >Leads to:
                    >
                    >http://www.jibbering.com/faq/faq_not..._dynwrite.html
                    >
                    >But you are correct, its not in the FAQ formal. For some reason, I
                    >thought it was added in the 4.15 but it is in the notes for that section.
                    >
                    >But, for curiosity sake, does it break anywhere in your IE4?[/color]

                    Not clear what "it" is. I guess you mean

                    if (document.all && !document.getEl ementById) { // untested-JRS
                    document.getEle mentById = function(id) {
                    return document.all[id] } }

                    I steer clear of using new browser-dependent code, for testability
                    reasons; DynWrite, much as in the FAQ, does what I need. So I don't
                    know.


                    Even with the FAQ's
                    document.getEle mentById("aID") .innerHTML= "Some <em>new</em> Content";
                    working, I would not use it amidst ordinary code, but would encapsulate
                    it in a function, say DynWr("anID", Str).


                    ** If I should go "off the air", it may be because of video failure. ***

                    --
                    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                    <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
                    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                    Comment

                    Working...