Parse HTML using .parseHTML()

.parseHTML()


Description: Parse HTML into an HTMLCollection


Example:

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>now demo</title>
      <script src="http://code.bitsycode.com/bitsycode-latest.min.js"></script>
    </head>
    <body>
      
      <div class="container"></div>
      
      <script>
         
        bitsyCode.ready(function(){
            
            var htmlCollection = bitsyCode.parseHTML('<!DOCTYPE html><html><head><title>Title Tag</title></head><body><a href="#">Anchor Tag</a><p>Paragraph Tag</p><b>Bold Tag</b></body></html>', true);
            for (var i=0; i < htmlCollection.length; i++) {
                bitsyCode(".container").append(bitsyCode(htmlCollection[i]).text() + "<br />");
            }
            
        })
         
      </script>
     
    </body>
    </html>

Preview:

Title Tag
Anchor Tag
Paragraph Tag
Bold Tag
  • Usage

    • How to use:

      Parse HTML and return either an HTMLCollection or an Array of children elements

    • Simple ( Returns an HTMLCollection[] ):

      bitsyCode.parseHTML('<b>HTML Content</b>');
    • Return an Array[]: You will need to pass through a true as an option.

      bitsyCode.parseHTML('<b>HTML Content</b>', true);
  • Options

    • What options are there:

      You will need to pass through a true, if you require the return type to be an array.

  • Returns

    • Returns: HTMLCollection[] or Array[ ], of HTML children
Share