I am having the following CSS Full selector "body > div > p" I need to fetch the element using the above css selector using javascript/jquery. Is there any built in function available to achive this ?
Asked
Active
Viewed 115 times
-5
-
2`$("body > div > p")`? – Anurag Srivastava Apr 12 '20 at 15:11
-
1In plain JS you can use `document.querySelector('body > div > p')` or `document.querySelectorAll('body > div > p')` – palaѕн Apr 12 '20 at 15:16
-
1Seems like the kind of question that does not indicate any research effort – Anurag Srivastava Apr 12 '20 at 15:21
-
Does this answer your question? [Child selector using \`querySelectorAll\` on a DOM collection](https://stackoverflow.com/questions/10189903/child-selector-using-queryselectorall-on-a-dom-collection) – Zuckerberg Apr 12 '20 at 15:25
-
There is a mistake in my actual css slector, now the issue is resolved. thanks – Anoop AP Apr 12 '20 at 15:25
1 Answers
3
Single selection:
document.querySelector('body > div > p')
Multi selection (as array):
document.querySelectorAll('body > div > p')
These were pure JS.
If you want to use jQuery
$('body > div > p')

F.NiX
- 1,457
- 3
- 12
- 20