0
$('.child_1').parents('.parent').find('.child_2')

How do I call the above JQuery syntax using core javascript syntax?

I am calling the child_2 using child_1 who has a common parent

Atul Kumar
  • 149
  • 1
  • 3
  • 14

3 Answers3

0

$('.child_1').closest('.parent').find('.child_2');

closest() will get you the first parent that matches the given query string.

Catalin Iancu
  • 722
  • 5
  • 18
0

You can do like this:

$('.child_1').parents('.parent:first').find('.class:eq(1)');

First notice that I have used :first to determine the proper parent of the child_1. Then, I have put in eq(1) because child counting starts from 0;

Himanshu Upadhyay
  • 6,558
  • 1
  • 20
  • 33
0

Refer to this answer to Get parents of element in JS and then iterate over the parents to get their child using querySelector

var parents = getParents( document.getElementByClassName('.child_1')[0]);
var children = [];

parents.forEach(function (parent) {
    children.push(parent.querySelector('.child_2'));
});
Deepansh Sachdeva
  • 1,168
  • 9
  • 16