0

Let's say I have the following html code..

<html>
<head></head>
<body>  
  <div>
    <input type ="text">
    <img src = "pic.jpg">
    <a href ="index.html">Home</a>
  </div>
</body>
</html>

And I want to look at the nodes around an element that's on the same level. For example, from the above html code, is it possible to do something like...

 $("input").returnNodesOnSameLevel()

and it can return a list of nodes which here would contain [< input...>, < a...> ] ?

I'm using NodeJS's request module to grab the page source and then using Cheerio to do my parsing. The sibling() only returns nodes of the same tag name which makes sense. If there's a better module or another way to do this, please let me know.

Thank you.

Arrow
  • 691
  • 2
  • 7
  • 15

1 Answers1

2

If $("input").siblings() doesn't work, you could try: $("input").parent().children()

  • 1
    Yeah that worked. Both of them do actually. I messed up a variable name in my actual code which was why I was got the empty results which is why I thought siblings() didn't work. Anyways, thank you. – Arrow Jul 23 '15 at 23:14