javascript - How to check if the Selection object contains two sibling 'Div' or 'P' -
i want check condition in whether user selection has 2 or more div or paragraph sibling in it. breaking head on new dom stuffs. came across such situation before or can me algorithm or logic achieve . highly appreciated.
whatever asked here, please share code snippet. here make example achieve that. since did't post code, i'm not sure example provided meet expectations.
html
<div id="a">click me <p></p> <div></div> <div></div> </div>
js
$('#a').on('click', function(){ var div = $(this).children('div').length; var p = $(this).children('p').length; if(div >= 2) { alert('div exists : ' + div); //do stuff here } else { alert('i have div below two'); //do stuff here if below 2 } //same goes p });