title: Select sibling & parent with Cheerio
body: <p>I've been unable to get access to really simple pieces of HTML using cheerio, I just finished opening up the object <code>$(this)</code> object and tracking down exactly what I need. Now an error occurs when there is no object in the stack, like a sibling or child. What's the correct way to select the previous sibling, get it's name, href &amp; content, as well as the parent's css.</p>
  
  <pre><code>var code = $('code.lang-javascript, code.lang-js')
  dataSet.blocks = []
  code.map(function (i, elm) {
    var block = {}
    block.prevSiblingTag = $(this).parent().prev()[0].children[0].name
    block.prevSiblingHref = $(this).parent().prev()[0].children[0].attribs.href
    block.prevSiblingContent = $(this).parent().prev()[0].children[0].text()
    block.parentTag = $(this)[0].name
    block.parentClass = $(this)[0].attribs.class
    block.code = $(this).html()
    dataSet.blocks.push(block)
  })
  </code></pre>
  
  <p>I was doing this and it was just a mess.</p>
  
  <pre><code>var $parent = $($(this).parent().html())
  var $prevSibling = $($(this).parents().prev())
  var block = {}
  block.parentClass = $parent.attr('class')
  block.prevSibling = $prevSibling.html()
  block.code = $(this).html()
  </code></pre>