Is there a way to do this in jQuery?
const outer = document.querySelector('.outer');
const inner = outer.querySelector('.inner');
Is there a way to do this in jQuery?
const outer = document.querySelector('.outer');
const inner = outer.querySelector('.inner');
Sure
const $outer = $('.outer').first();
const $inner = $outer.find('.inner').first();
Of course the above will return two jQuery objects as opposed to DOM node references. If you want the node reference, just grab the first element in the collection:
const $outer = $('.outer').first();
console.log($outer);
console.log($outer[0]);
// Object { 0: div.outer, length: 1, prevObject: {…} }
// <div class="outer">
Out of interest, why do you want to do that? document.querySelector
is supported in all modern browsers and even in IE11.
Oh, thanks! One of the plugins I use doesn’t support vanilla js and only jquery.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.