What method can be used to select the first
element inside a
?
- div.getElementsByTagName('p')[0]
- div.querySelector('p:first-child')
- div.querySelector('p')
- div.getElementByTagName('p')
You can use div.querySelector('p') to select the first
element inside a
. This method finds the first
element that is a descendant of div. Alternatively, you can use getElementsByTagName('p')[0], but querySelector is more flexible and widely used.
Loading...
Related Quiz
- The arithmetic operator _______ increments the value of a variable by 1.
- You are working on a form validation feature where you want to select all input elements within a form. Which method allows you to select all input elements within a specific form element?
- Which method should be used to handle exceptions in an async/await function?
- You are developing an e-commerce website and want to fetch product details asynchronously to avoid page reloads. Which method might be appropriate for managing successive data retrieval operations in a clean and maintainable manner?
- Which API allows you to make non-simple requests to another domain in JavaScript, considering the Same-Origin Policy?