469,336 Members | 5,539 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

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.GetElementById("myDiv");
var xmlDoc = myDiv.implementation ; // to obtain dom of mydiv ?!
var nodeList = xmlDoc.selectNodes("hr") ;

is it possible with "microsoft internet explorer" ? (it works on gecko based
browsers)
Jul 23 '05 #1
9 4711
marc wrote:
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.GetElementById("myDiv");
var xmlDoc = myDiv.implementation ; // to obtain dom of mydiv ?!
var nodeList = xmlDoc.selectNodes("hr") ;

is it possible with "microsoft internet explorer" ?


http://msdn.microsoft.com/workshop/a...ppendchild.asp
http://msdn.microsoft.com/workshop/a...emovechild.asp

function remove() {
var target=document.getElementById('myDiv');
target.removeChild(target.childNodes[0]);
}
function add(){
var target=document.getElementById('myDiv');
var oHR=document.createElement("HR");
target.appendChild(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

Jul 23 '05 #2
"mscir" <ms***@access4less.com.net.org.uk> a écrit dans le message de news:
10*************@corp.supernews.com...
marc wrote:
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.GetElementById("myDiv");
var xmlDoc = myDiv.implementation ; // to obtain dom of mydiv ?!
var nodeList = xmlDoc.selectNodes("hr") ;

is it possible with "microsoft internet explorer" ?

http://msdn.microsoft.com/workshop/a...ods/appendchil
d.asp http://msdn.microsoft.com/workshop/a...ods/removechil
d.asp
function remove() {
var target=document.getElementById('myDiv');
target.removeChild(target.childNodes[0]);
}
function add(){
var target=document.getElementById('myDiv');
var oHR=document.createElement("HR");
target.appendChild(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


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.selectNodes("/hr"); ...
but IE doesn't like that ?!?
Jul 23 '05 #3
// note capitalization difference
var myDiv = document.getElementById("myDiv");
var myNodes = myDiv.getElementsByTagName('HR');

Csaba Gabor

"marc" <Ma********@ctrceal.caisse-epargne.fr> wrote in message
news:c6**********@s1.read.news.oleane.net...
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.GetElementById("myDiv");
var xmlDoc = myDiv.implementation ; // to obtain dom of mydiv ?!
var nodeList = xmlDoc.selectNodes("hr") ;

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

Jul 23 '05 #4
marc wrote:
"mscir" <ms***@access4less.com.net.org.uk> a écrit dans le message de news:
10*************@corp.supernews.com...
marc wrote:
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.GetElementById("myDiv");
var xmlDoc = myDiv.implementation ; // to obtain dom of mydiv ?!
var nodeList = xmlDoc.selectNodes("hr") ;

is it possible with "microsoft internet explorer" ?


http://msdn.microsoft.com/workshop/a...ods/appendchil
d.asp

http://msdn.microsoft.com/workshop/a...ods/removechil
d.asp

function remove() {
var target=document.getElementById('myDiv');
target.removeChild(target.childNodes[0]);
}
function add(){
var target=document.getElementById('myDiv');
var oHR=document.createElement("HR");
target.appendChild(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


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.selectNodes("/hr"); ...
but IE doesn't like that ?!?


<body onload="a();">
<div id="myDiv"> <hr> <hr> <hr> <hr> </div>
<script>
function a() {
var output = [];
if (document.getElementById) {
var div = document.getElementById('myDiv');
if (div && div.getElementsByTagName) {
var divHRs = div.getElementsByTagName('hr');
if (divHRs) {
for (var i = 0; i < divHRs.length; i++) {
output.push(divHRs[i].nodeName);
}
}
}
}
alert(output.join('\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 getElementsByTagName().

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* 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
Jul 23 '05 #5
you can get the list of the HR tags inside myDiv using the
getElementsByTagName:

var myDiv = document.getElementById("myDiv");
var nodeList = myDiv.getElementsByTagName("HR");

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

"marc" <Ma********@ctrceal.caisse-epargne.fr> wrote in message news:<c6**********@s1.read.news.oleane.net>...
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.GetElementById("myDiv");
var xmlDoc = myDiv.implementation ; // to obtain dom of mydiv ?!
var nodeList = xmlDoc.selectNodes("hr") ;

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

Jul 23 '05 #6
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"(evaluate)
in a html document...
and if i wanna port it to IE, i should replace all xpath expressions by some
getelementstagbyname ;-(
"sharon" <sh****@athoc.com> a écrit dans le message de news:
84**************************@posting.google.com...
you can get the list of the HR tags inside myDiv using the
getElementsByTagName:

var myDiv = document.getElementById("myDiv");
var nodeList = myDiv.getElementsByTagName("HR");

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

"marc" <Ma********@ctrceal.caisse-epargne.fr> wrote in message

news:<c6**********@s1.read.news.oleane.net>...
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.GetElementById("myDiv");
var xmlDoc = myDiv.implementation ; // to obtain dom of mydiv ?!
var nodeList = xmlDoc.selectNodes("hr") ;

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

Jul 23 '05 #7
JRS: In article <dL********************@comcast.com>, seen in
news:comp.lang.javascript, Randy Webb <hi************@aol.com> posted at
Tue, 18 May 2004 19:39:02 :
The FAQ has a section that explains how to emulate
getElementById in IE4, and to date, there have been no posts about it
failing.


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.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #8
Dr John Stockton wrote:
JRS: In article <dL********************@comcast.com>, seen in
news:comp.lang.javascript, Randy Webb <hi************@aol.com> posted at
Tue, 18 May 2004 19:39:02 :

The FAQ has a section that explains how to emulate
getElementById in IE4, and to date, there have been no posts about it
failing.

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.


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?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #9
JRS: In article <R_********************@comcast.com>, seen in
news:comp.lang.javascript, Randy Webb <hi************@aol.com> posted at
Wed, 19 May 2004 15:53:08 :
Dr John Stockton wrote:
JRS: In article <dL********************@comcast.com>, seen in
news:comp.lang.javascript, Randy Webb <hi************@aol.com> posted at
Tue, 18 May 2004 19:39:02 :

The FAQ has a section that explains how to emulate
getElementById in IE4, and to date, there have been no posts about it
failing.

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.


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?


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

if (document.all && !document.getElementById) { // untested-JRS
document.getElementById = 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.getElementById("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.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by James Marshall | last post: by
8 posts views Thread by pierre | last post: by
reply views Thread by Filippo Bettinaglio | last post: by
reply views Thread by thompson_38 | last post: by
9 posts views Thread by Le Minh | last post: by
5 posts views Thread by Jeff | last post: by
2 posts views Thread by CSharper | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.