Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Perform $('.div a') in Vanilla JavaScript?

Like the title says, I am looking for a quick way to write following jQuery code $('.div a') in "plain" JavaScript. I know we can do getElementsByClassName to find .div, but how about finding the link it contains?

like image 525
user997309 Avatar asked Dec 04 '25 12:12

user997309


1 Answers

Browsers have a native method for accomplishing this:

document.querySelectorAll( ".div a" );

You can retrieve only the first match with querySelector.

like image 168
Sampson Avatar answered Dec 07 '25 02:12

Sampson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!