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


Groups > comp.lang.javascript > #39208

Re: Accessing DIV value on current document

From Jake Jarvis <pig_in_shoes@yahoo.com>
Newsgroups comp.lang.javascript
Subject Re: Accessing DIV value on current document
Date 2020-11-27 14:02 +0100
Organization A noiseless patient Spider
Message-ID <rpqtd8$bl0$1@dont-email.me> (permalink)
References <0af79463-50bf-47e3-9e64-16639ec109edn@googlegroups.com> <querySelector-20201127133538@ram.dialup.fu-berlin.de> <XnsAC828C9F45D95eejj99@194.109.6.166>

Show all headers | View raw


Am 27.11.2020 um 13:49 schrieb Evertjan.:
> 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');
> 
> 

that last one looks wrong, doesn't it?

there is no OUTERBOX element
there are no classes C1 and C2

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