Re: Reading value from label (DIV) with JS
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Reading value from label (DIV) with JS

From: RobG <rgqld@iinet.net.auau>
Date: Tue Aug 09 2005 - 03:01:59 CEST

Mateo wrote:
> Thx man!
>
> Still there is one problem with this approach... And the problem is like you
> said, when
> element contains other stuff... then I'm not quite sure that first child
> node is textnode.

>
> I have huge code, and I prefer not to change it, which goes through elements
> on page,
> and reading/changing values according to some rules. Somethimes there is
> posibility
> that current control is not empty (label is actually DIV, and DIV is
> container) becouse
> those are dinamically generated controls in very complex asp.net
> application.
>
> Someone wrote this code last year and left the company, and I'm trying to
> make it Mozilla
> compatibile without making changes in concepts and algorithms.
>
> So if u have any other idea besides firstChild.nodeValue I would be very
> grateful.....
> If not, I can try to use this with some aditional handling....
> Thx anywway...

You can make a reasonable version of innerText using a regular
expression and innerHTML:

  var re = /<[^<>]+>/g;
  var iText = theDiv.innerHTML.replace(re,'');

If you have form controls with text content (e.g. textarea or option
elements) it will be best to not have them inside the label or the
above will return their text too (I don't know what innerText does
with that).

DOM 3 has 'textContent', but I don't think it's particularly well
supported just yet - v. 1.0 became a recommendation in April 2004.

-- 
Rob
Received on Tue Oct 18 03:06:47 2005