[英]How to check if the Selection object contains two sibling 'Div' or 'P'
I want to check a condition in which whether the user selection has any two or more div or paragraph sibling in it. 我想检查用户选择中是否有两个或多个div或段落同级的条件。 am breaking my head on this am new to dom stuffs.
在这对dom东西很陌生的方面让我很头疼。 Anybody came across such situation before or somebody can help me with the algorithm or logic to achieve this .
任何人都曾经遇到过这种情况,或者有人可以帮助我实现该目标的算法或逻辑。 any help is highly appreciated.
非常感谢您的帮助。
Whatever you asked here, please share code snippet. 无论您在此处提出什么要求,请共享代码段。 Here i make for you example to achieve that.
在这里,我为您提供实现此目标的示例。 Since you did't post any code, then i'm not sure the example provided meet the expectations.
由于您未发布任何代码,因此我不确定所提供的示例是否符合预期。
HTML HTML
<div id="a">Click me
<p></p>
<div></div>
<div></div>
</div>
JS 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 your stuff here
}
else
{
alert('i have div below than two');
//do your stuff here if below than two
}
//same goes with p
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.