Find similar HTML parts

I have following (simplified) HTML code and want to split it into similar parts:\[code\]<input id="checkbox1"><label><br><input id="checkbox2"><label><br><input id="checkbox3"><label><br>\[/code\]The result for this should be \[code\]<input><label><br>\[/code\]. But the problem is, I need a bulletproof solution, which would for example return \[code\]<div><p><input></p><p><label></p><div>\[/code\] from the following HTML:\[code\]<div><p><input id="checkbox1"></p><p><label></p><div><div><p><input id="checkbox2"></p><p><label></p><div><div><p><input id="checkbox3"></p><p><label></p><div>\[/code\]Any idea how to find such a pseudo parent element in JavaScript/jQuery?
 
Back
Top