I’m looking for an advanced function to select elements in the dom without using jQuery or any other library.
Something that will accomplish the same thing that the $(selector) function does in jQuery.
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The best thing you can use is
querySelectorAll, which allows you to select using a CSS selector, just as you would with jQuery:You would then need to loop through
linksto do whatever you wanted to do to the elements. Note that a lot of jQuery-provided utility functions (e.g.addClass) will not be available. Some utility functions are available in modern browsers (and more will come when DOM4 is adopted) but it will be a lot clunkier than jQuery makes it. That’s the price you’ll pay.