Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #39206

Re: Accessing DIV value on current document

Newsgroups comp.lang.javascript
Subject Re: Accessing DIV value on current document
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <0af79463-50bf-47e3-9e64-16639ec109edn@googlegroups.com> <querySelector-20201127133538@ram.dialup.fu-berlin.de>
Date 2020-11-27 13:49 +0100
Message-ID <XnsAC828C9F45D95eejj99@194.109.6.166> (permalink)

Show all headers | View raw


ram@zedat.fu-berlin.de (Stefan Ram) wrote on 27 Nov 2020 in 
comp.lang.javascript:

> Tatsujin <tatsujin.3.r@gmail.com> writes:
>><div class="outerbox">
>>  <div class="c1">Some words here</div>
>>  <div class="c2">More words here</div>
>></div>
>>How do I access (or get a reference to) the text value in DIV class "C2"?
>>I thought maybe it was "document.c2.value", but I was wrong.
> 
>   I'd suggest to add an id to it and then use »getElementById«.
> 
>   Otherwise, something like
> 
> document.getElementsByClassName( "c2" )[ 0 ]
> 
>   or
> 
> document.querySelector( "div.outerbox > div.c2" )
> 
>   might work, depending on what else is contained in that document.

const C2 = document.querySelectorAll('.C2')[0]; // or other number

or

const C2 = document.querySelectorAll('div')[2]; // or other number

or

const outerbox = document.querySelector('outerbox');
const C1 = outerbox.querySelector('.C1');
const C2 = outerbox.querySelector('.C2');


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Accessing DIV value on current document Tatsujin <tatsujin.3.r@gmail.com> - 2020-11-26 23:42 -0800
  Re: Accessing DIV value on current document "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-11-27 13:49 +0100
    Re: Accessing DIV value on current document Jake Jarvis <pig_in_shoes@yahoo.com> - 2020-11-27 14:02 +0100
      Re: Accessing DIV value on current document Tatsujin <tatsujin.3.r@gmail.com> - 2020-11-27 11:19 -0800
  Re: Accessing DIV value on current document Jake Jarvis <pig_in_shoes@yahoo.com> - 2020-11-27 13:55 +0100

csiph-web