0

I'm taking a course that uses the queryselectorall tool, and I was a doubt about his statement! The space between .seat.selected produces the desired effect

function updateSelectedCount() {
    const selectedSeats = document.querySelectorAll('.row .seat.selected')
    const selectedSeatsCount = selectedSeats.length
    console.log(selectedSeatsCount)
}

But if I put a space between them,nothing happens

function updateSelectedCount() {
    const selectedSeats = document.querySelectorAll('.row .seat .selected')
    const selectedSeatsCount = selectedSeats.length
    console.log(selectedSeatsCount)
}

the space between classes does what in the code?

Phil
  • 141,914
  • 21
  • 225
  • 223

2 Answers2

2

.seat.selected that mean two class .seat and .selected in only one div

.seat .selected that mean div .seat is parent of div .selected

Hien Nguyen
  • 23,011
  • 7
  • 48
  • 55
1

The first example is looking for something like this

<div class="row">
<div class="seat selected">

where the 2nd is

<div class="row">
<div class="seat">
<div class="selected">
Daniel A. White
  • 181,601
  • 45
  • 354
  • 430