• Status: Solved
  • Priority: High
  • Security: Private
  • Views: 51
  • Last Modified:

How can I get elements in jQuery with parent/child

I am writing some javascript tests and I would like to do the below using jQuery, $('.parent .child'); can someone assist?

"has at least 1 entry after loadFeed function is called"

it(".feed container has at least 1 entry", function(done) { 
       var numEntries = document.querySelector(".feed").getElementsByClassName("entry").length;   //use jquery parent/child here
       expect(numEntries).toBeGreaterThan(0); 
       done(); 
     }); 

Open in new window

0
earwig75
Asked:
earwig75
  • 2
1 Solution
 
Julian HansenCommented:
$('element').parent() will give you the parent of an element.
$'('element').parent().children() will give you all the children of that parent element
$('element').siblings() will return all the children of the parent except this one.

Not really sure what you are asking?
0
 
earwig75Author Commented:
Sorry, I figured it out. I was looking for this:

expect($('.feed .entry').length).toBeGreaterThan(0);

Open in new window

0
 
earwig75Author Commented:
Posted answer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now