JSFiddle - React, Tailwind, and code Playground

by gaurav_ashara

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

JavaScript

var result = [];
function doStuff(child) {
//		  console.log(child);
		}

function walk(children) {


  if (typeof children == "undefined") {
    return;
  }
  $.each( children,function(i, el){
		console.log(el);
		if(el.nodeName == "#text")
    	result[result.length] = el.textContent;
      
    if (el.childNodes.length > 0) {
      walk(el.childNodes);
    }
    doStuff(el);
  })
}


var demo = 'Hello1<div>Hello2<div>Hello3</div></div>'
html = $.parseHTML( demo);


walk(html);
		 nodeNames = [];
		//console.log(html)

		
		//walk(html);



		$.each( html, function( i, el ) {
			
			//console.log(el.childNodes + " " + el.nodeName)	;
      
/*			if(el.nodeName == "#text")
				console.log(el.textContent);	
			else	
				console.log(el.tagName);	
			//console.log(el.tagName);	
      */
		  nodeNames[ i ] = "<li>" + el.nodeName + "</li>";
		});