title: How to remove <div> and <br> using Cheerio js?
body: <p>I have the following html that I like to parse through Cheerios.</p>
  
  <pre><code>    var $ = cheerio.load('&lt;html&gt;&lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/&gt;&lt;/head&gt;&lt;body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"&gt;&lt;div&gt;This works well.&lt;/div&gt;&lt;div&gt;&lt;br clear="none"/&gt;&lt;/div&gt;&lt;div&gt;So I have been doing this for several hours. How come the space does not split? Thinking that this could be an issue.&lt;/div&gt;&lt;div&gt;Testing next paragraph.&lt;/div&gt;&lt;div&gt;&lt;br clear="none"/&gt;&lt;/div&gt;&lt;div&gt;Im testing with another post. This post should work.&lt;/div&gt;&lt;div&gt;&lt;br clear="none"/&gt;&lt;/div&gt;&lt;h1&gt;This is for test server.&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;', {
      normalizeWhitespace: true,
  });
  
  // trying to parse the html
  // the goals are to 
  // 1. remove all the 'div'
  // 2. clean up &lt;br clear="none"/&gt; into &lt;br&gt;
  // 3. Have all the new 'empty' element added with 'p'
  
  var testData = $('div').map(function(i, elem) {
      var test = $(elem)
      if ($(elem).has('br')) {
          console.log('spaceme');
          var test2 = $(elem).removeAttr('br');
      } else {
          var test2 = $(elem).removeAttr('div').add('p');
      }
      console.log(i +' '+ test2.html());
      return test2.html()
  })
  
  res.send(test2.html())
  </code></pre>
  
  <p>My end goals are to try and parse the html</p>
  
  <ul>
  <li>remove all the div</li>
  <li>clean up <code>&lt;br clear="none"/&gt;</code> and change into <code>&lt;br&gt;</code></li>
  <li>and finally have all the empty 'element' (those sentences with 'div') remove to be added with 'p' sentence '/p'</li>
  </ul>
  
  <p>I try to start with a smaller goal in the above code I have written. I tried to remove all the 'div' (it is a success) but I'm unable to to find the 'br. I been trying out for days and have no head way. </p>
  
  <p>So I'm writing here to seek some help and hints on how can I get to my end goal.</p>
  
  <p>Thank you :D</p>