On Apr 3, 8:11 pm, "Evertjan." <exjxw.hannivo...@interxnl.net> wrote:
> 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
|