473,804 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting Entire Node

If I had a span tag like:

<span id='msg_2'>
There is a bunch of text <a href="http://www.someurl.com "> here </a>. And
some others <a href="http://www.otherurl.co m">here</a>. Good luck!
</span>

And it contains other tags in it.

If I use: document.getEle mentById('msg_2 ').firstChild.n odeValue
then I just get: "There is a bunch of text".

I'd like to get the total node contained between the span tag.

Anyone know how I can get this?

Mike
Jul 23 '05 #1
4 1474
This works:

document.getEle mentById('msg_2 ').innerHTML

But is it correct?

"Michael Hill" <hi****@charter .net> wrote in message
news:10******** *****@corp.supe rnews.com...
If I had a span tag like:

<span id='msg_2'>
There is a bunch of text <a href="http://www.someurl.com "> here </a>. And
some others <a href="http://www.otherurl.co m">here</a>. Good luck!
</span>

And it contains other tags in it.

If I use: document.getEle mentById('msg_2 ').firstChild.n odeValue then I
just get: "There is a bunch of text".

I'd like to get the total node contained between the span tag.

Anyone know how I can get this?

Mike

Jul 23 '05 #2
Michael Hill wrote:
This works:

document.getEle mentById('msg_2 ').innerHTML

But is it correct?

[...]

If you want the HTML contained between the <span> </span> tags, yes.

When you do:

document.getEle mentById('msg_2 ').innerHTML = 'some text'

the entire content between the tags is replaced by 'some text'. You
can put HTML in there to:

document.getEle mentById('msg_2 ').innerHTML = '<b>some<br>tex t</b>'

and so on.

But if you want to manipulate the contents using DOM, you need to do
something like:

var theNodes = document.getEle mentById('msg_2 ').childNodes

'theNodes' will be a collection of the nodes of 'msg_2'. Note that it
will be a collection of the direct children of msg_2, you need other
DOM methods to get at lower nodes:

theNodes[0].childNodes[0]

will return the first child of the first child of msg_2.

Fred.
Jul 23 '05 #3

"Fred Oz" <oz****@iinet.n et.auau> wrote in message
news:41******** **************@ per-qv1-newsreader-01.iinet.net.au ...
Michael Hill wrote:
This works:

document.getEle mentById('msg_2 ').innerHTML

But is it correct?

[...]

If you want the HTML contained between the <span> </span> tags, yes.

When you do:

document.getEle mentById('msg_2 ').innerHTML = 'some text'

the entire content between the tags is replaced by 'some text'. You
can put HTML in there to:

document.getEle mentById('msg_2 ').innerHTML = '<b>some<br>tex t</b>'

and so on.

But if you want to manipulate the contents using DOM, you need to do
something like:

var theNodes = document.getEle mentById('msg_2 ').childNodes

'theNodes' will be a collection of the nodes of 'msg_2'. Note that it
will be a collection of the direct children of msg_2, you need other
DOM methods to get at lower nodes:

theNodes[0].childNodes[0]

will return the first child of the first child of msg_2.

Fred.


Fred,

That is what I was thinking. Appreciate you.

Mike
Jul 23 '05 #4
document.getEle mentById returns a ref to the
entire node including its childNodes which
can be referenced through the childNodes
collection of the DOM. Read up on DOM Level 2.
<http://www.howtocreate .co.uk/tutorials/index.php?tut=0 &part=25>
You will find references and examples.
Also different browsers will treat spaces in
your markup as separate text nodes so be
careful with your tags and leaving spaces.
I'm no expert on this but this should
help. Tested in IE6. Just run it and then
inspect the code. Watch out for word wrap!
Jimbo
<HTML>
<HEAD><TITLE> </TITLE>
</HEAD>
<BODY>
<span id='msg_2'>Ther e is a bunch of text
<a href="http://www.someurl.com ">here</a>
.. And some others
<a href="http://www.otherurl.co m">here</a>
.. Good luck!</span>
<script type="text/javascript">
var obj = document.all?ms g_2:document.ge tElementById('m sg_2');
var len = obj.childNodes. length;
alert('the node msg_2 has '+
len +' childNodes');
for (var i=0; i<len; i++) {
var el = obj.childNodes[i];
var nType = el.nodeType;
if( nType== 1) { // element
if( el.childNodes.l ength ) {
var more = 'with ' +
el.childNodes.l ength +
' childNodes\n' +
'obj.childNodes[' + i +
'].firstChild.nod eValue = ' +
el.firstChild.n odeValue;
}
alert('obj.chil dNodes['+i+'] is a <' +
el.tagName +
'> element\n'+ more);
}
if(nType == 3) { // text node
alert('obj.chil dNodes['+i+'] is a text node\n'+
'obj.childNodes[' +i+ '].nodeValue = ' +
el.nodeValue);
}
}
</script>
</BODY>
</HTML>
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2160
by: F. Da Costa | last post by:
Hi, I' looking to retrieve ProdName1 form the <tr> below. <tr id="1-1-1" class="even"> <td> <div class="tier4"> <a href="#" class="leaf"></a> ProdName1 </div>
6
1710
by: Affan Syed | last post by:
Hi, I am getting this weird problem. I know what i am doing is strange.. i am using C++ vectors and fopen, but for some reason if i used ofstream in the similar scenario it would give me errors. So here is what i do. I create a new node and insert it in a vecotr as follows: nodeCreator = new cNode(location, skew, offset,Beaconify,nodeId,directory); gNodeVector.push_back(*nodeCreator); //now lets delete the memory we created for the node
4
12235
by: leodippolito | last post by:
Hello sirs, I am trying to send a POST request to a webservice on the click of a button. This will return me an XML document with a list of combo box items. The problem: in FIREFOX, when the get the XmlDocument from the XmlHttpRequest object, I can't access its contents. I keep getting empty strings and "null".
7
2218
by: Steven Bethard | last post by:
How do I make sure that my entire string was parsed when I call a pyparsing element's parseString method? Here's a dramatically simplified version of my problem: py> import pyparsing as pp py> match = pp.Word(pp.nums) py> def parse_num(s, loc, toks): .... n, = toks .... return int(n) + 10 ....
5
2250
by: DarthDaddy | last post by:
I hope to explain this properly. Here is a sample section of a file I am working with: <achievements> <achievement> <item name="COURSE_COMPLETION_DATE">19930630</item> <item name="COURSE_CODE">ADA1W0</item> <item name="SECTION_NUMBER">33</item> <item name="COURSE_DESC_CODE"/> <item name="COURSE_TYPE">DS</item>
3
1623
by: Eroc | last post by:
I'm new to XML files so I'm kinda lost here. I found some example code on reading an XML file. My objective is simple. Read the whole XML file into memory. Here is part of my code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim query As String
4
4515
by: R.Manikandan | last post by:
Hi In my code, one string variable is subjected to contain more amount of characters. If it cross certain limit, the string content in the varabile is automatically getting truncated and i am not getting the full data. Is there any max limit for an variable to store in javascript? Can anyone please help me to solve this prob?
2
2055
by: Bardo | last post by:
Hi all, Does anyone know if it is possible, and if so how, to perform validation of a simple non XML string against certain XSD restrictions, without having the entire XML document to validate against the schema. To elaborate - - Within XSD certain restrictions are defined for a particular element/attribute, such as datatype, minlength, maxlength, valid enumeration values etc. Is it at all possible to validate a simple string value...
0
985
by: ullner | last post by:
I have an XML fil that looks like this: <Environment> <AreaOfInterest> <Name>ScenarioMap</Name> <UpperRight> <GDC> <Latitude>-179</Latitude> <Longitude>-179</Longitude>
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10097
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.