Advanced selectors of the DOM element in JavaScript

Let's do something more complicated. Let, for example, we have the following HTML code:

html<div id="parent">
  <input>
</div>

Let's get a reference to the input located inside the block #parent:

javascriptlet elem = document.querySelector('#parent input');
console.log(elem);

As you can see, we got our input using the #parent input selector. In fact, all inputs that are in #parent match this CSS selector.

Let, for example, we have two such inputs:

html<div id="parent">
  <input value="1">
  <input value="2">
</div>

Then, if we write the selector #parent input in the CSS code, it will affect both of our inputs:

css#parent input {
  color: red;
}

The querySelector method, however, does not work that way. It always gets only one element - the first one that matches the specified selector. Let's look at an example. Let's say we have inputs with class elem:

html<input class="elem">
<input class="elem">

Let's get the first of these inputs:

javascriptlet elem = document.querySelector('.elem');
console.log(elem); // here will be the first input
Задание 1

Given the following HTML:

html<div id="block">
  <p>1</p>
  <p>2</p>
</div>

Get a reference to the first paragraph from a div with id equal to block.

Задание 2

Given the following HTML:

html<div class="block">
  <p>1</p>
  <p>2</p>
</div>

Get a reference to the first paragraph from a div with the class block.

Задание 3

Given the following HTML:

html<p class="www">text</p>
<p class="www">text</p>

Get a reference to the first paragraph with the class www.