473,466 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why won't this work

I have this HTML fragment

The <abbr title="World Wide Web Consortium">W3C</abbr>

When I try to get the textNode's value, I keep getting an error saying
"object required". On debugging it fails when trying to fet the
lastChild.nodeValue

//This works, I get an element node
var currentAbbr = abbrs[i];
//This also works and sys World Wide Web Consortium"
var abbrTitle = currentAbbr.getAttribute("title");
//*** This fails ***
var abbrText = currentAbbr.lastChild.nodeValue;

Any hints are greatly appreciated.

thanks
Sunit

Apr 3 '07 #1
2 1155
sjoshi wrote on 03 apr 2007 in comp.lang.javascript:
I have this HTML fragment

The <abbr title="World Wide Web Consortium">W3C</abbr>

When I try to get the textNode's value, I keep getting an error saying
"object required". On debugging it fails when trying to fet the
lastChild.nodeValue
Always state the browser and the error text, please.
//This works, I get an element node
var currentAbbr = abbrs[i];
I doubt that, not under IE7.

Use:

var currentAbbr = document.getElementsByTagName('abbr')[i];

//This also works and sys World Wide Web Consortium"
var abbrTitle = currentAbbr.getAttribute("title");
var abbrTitle = currentAbbr.title;

works just as nice.
//*** This fails ***
var abbrText = currentAbbr.lastChild.nodeValue;
works fine here [IE7]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 3 '07 #2
On Apr 3, 8:11 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
sjoshi wrote on 03 apr 2007 in comp.lang.javascript:
I have this HTML fragment
The <abbr title="World Wide Web Consortium">W3C</abbr>
When I try to get the textNode's value, I keep getting an error saying
"object required". On debugging it fails when trying to fet the
lastChild.nodeValue
[...]
//*** This fails ***
var abbrText = currentAbbr.lastChild.nodeValue;

works fine here [IE7]
But not in IE 6, it seems to believe that the abbr element doesn't
have a child node.

The OP should really be using textContent or innerText as the text
within the abbr could easily be styled by some other in-line element,
e.g.:

<abbr onclick="alert(getText(this));"
style="font-weight: bold;"><span
style="color: blue;">W3</span>C</abbr>

<script type="text/javscript">
function getText(el)
{
if (typeof el.textContent == 'string')
return el.textContent;
if (typeof el.innerText == 'string')
return el.innerText;
if (typeof el.innerHTML == 'string' )
return el.innerHTML.replace(/<[^>]*>/g,'');
return '';
}
</script>

--
Rob

Apr 3 '07 #3

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

Similar topics

16
by: Kerry Neilson | last post by:
For the past couple of months, Idle won't start when I invoke it. I am at a complete loss for why this is. When this happens, they python command line still starts, and python works fine...
1
by: Jim | last post by:
Hey guys I DESPERATLY need some help with this small javascript i have on this website. All that it's supposed to do is change the button image once it's pressed but alas... I copy-pasted the code...
3
by: DFS | last post by:
I've been working around this for years (I believe), so I figured someone here might know: Why won't a crosstab query accept a value from a form reference? TRANSFORM...
7
by: simon | last post by:
I have simple html(aspx) page, but vertical height won't work. Even if i had set the height of a table=100%, the table is not 100% height. I spend a lot of time(my real page is more...
3
by: musosdev | last post by:
Hi guys Okay, I've setup my projects to open and compile fine in VS2005 using FPSE and remote web, but it's *really* slow. So I thought I'd have a go at doing it the normal way, by loading from...
11
by: John Ortt | last post by:
Hi everyone. I have a database which I have developed in Access 2000 which is working nicely. The problem is that my customer only has Access 97. I tried to convert the database but the main...
7
by: Eran.Yasso | last post by:
Hi, I have project that automate excel(using Excel COM) which works fine in my home. I took the project from my home to work and tried to build the project but it won't built. I get error "The...
2
by: scitrenbaum | last post by:
Here is the dilemma. I have a website where everything works perfectly in all browsers except for Safari. When you are in Safari and you go to this page... ...
2
tpgames
by: tpgames | last post by:
Two days ago, MS office Word would type JP fonts, I thought. I didn't think I was using Works. Now, it won't type in JP. Jasc Paint shop pro 8, should type JP fonts because I am using XP, according...
4
by: z55177 | last post by:
My domain: http://www.esthevision.cz/ This is the cause of my problem. The template is supposed to look somewhat like this: PINK STRIPE http://themebot.com/website-templates/ht... I created an...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
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 ...

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.