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
  • 157,677
  • 23
  • 242
  • 245

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
  • 24,551
  • 7
  • 52
  • 62
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
  • 187,200
  • 47
  • 362
  • 445