admin管理员组文章数量:1022761
hi i have a div tag with nested divs as shown below
<div class="friendRequestMenu" id="friendRequestMenu">
<div class="toolbarTitle">
<span>Friend Requests</span> <a href="javascript:void(0)" class="hyperlink">Find Friends</a>
</div>
<div id="friendRequestData">
<!-- put div class=requestli to see a block-->
<div class="no-request">
No New Friend Requests
</div>
<a href="javascript:void(0)">
<div class="see-all-requests">
See All Requests
</div>
</a>
</div>
</div>
javascript:
$('*').each(function() { /getting all elements in document
// do something for all elements except the div tag above
});
i want the code to apply for everything except for the div tag and its children, i know i can get all the id's and add an exception , but i want to do that with only the parent tag thanks EDIT:
hi this is exactly what i want to do
$(document.body).find('*:not(#friendRequestMenu):not(#friendRequestMenu *)').each(function () {
var clientWidth = $(window).width();
var clientHeight = $(window).height();
var heightPercent = ($(this).height() / clientHeight) * 100;
var widthPercent = ($(this).width() / clientWidth) * 100;
$(this).css('height', heightPercent.toString());
$(this).css('width', widthPercent.toString());
});
but i want to ignore some elements, as you can see the selector part code isnt working for me
hi i have a div tag with nested divs as shown below
<div class="friendRequestMenu" id="friendRequestMenu">
<div class="toolbarTitle">
<span>Friend Requests</span> <a href="javascript:void(0)" class="hyperlink">Find Friends</a>
</div>
<div id="friendRequestData">
<!-- put div class=requestli to see a block-->
<div class="no-request">
No New Friend Requests
</div>
<a href="javascript:void(0)">
<div class="see-all-requests">
See All Requests
</div>
</a>
</div>
</div>
javascript:
$('*').each(function() { /getting all elements in document
// do something for all elements except the div tag above
});
i want the code to apply for everything except for the div tag and its children, i know i can get all the id's and add an exception , but i want to do that with only the parent tag thanks EDIT:
hi this is exactly what i want to do
$(document.body).find('*:not(#friendRequestMenu):not(#friendRequestMenu *)').each(function () {
var clientWidth = $(window).width();
var clientHeight = $(window).height();
var heightPercent = ($(this).height() / clientHeight) * 100;
var widthPercent = ($(this).width() / clientWidth) * 100;
$(this).css('height', heightPercent.toString());
$(this).css('width', widthPercent.toString());
});
but i want to ignore some elements, as you can see the selector part code isnt working for me
Share Improve this question edited Jul 20, 2011 at 5:21 Yohann asked Jul 19, 2011 at 14:46 YohannYohann 1362 silver badges13 bronze badges 2- If you take out the div tags and their children, then there's nothing left. – Oswald Commented Jul 19, 2011 at 14:49
-
2
I would suggest you reconsider if using the
*
selector is a good idea. Maybe what you want to do is possible without iterating over the zillion elements that make up a production web page? – Jon Commented Jul 19, 2011 at 14:49
3 Answers
Reset to default 5$('*:not(#friendRequestMenu):not(#friendRequestMenu *)').each(...);
Using the :not()
selector should handle this nicely.
The simplest forms are as follows:
$(':not(#friendRequestMenu, #friendRequestMenu *)').each(...);
and
$('*').not('#friendRequestMenu, #friendRequestMenu *');
The second version is likely to be more efficient as I don't believe that the browser's native implementation of querySelectorAll
supports :not(...)
. Don't bother optimizing unless you have an issue with how long the query takes.
Try this
$('*').not("#friendRequestMenu, #friendRequestMenu *").each(function(){
//do something here
});
hi i have a div tag with nested divs as shown below
<div class="friendRequestMenu" id="friendRequestMenu">
<div class="toolbarTitle">
<span>Friend Requests</span> <a href="javascript:void(0)" class="hyperlink">Find Friends</a>
</div>
<div id="friendRequestData">
<!-- put div class=requestli to see a block-->
<div class="no-request">
No New Friend Requests
</div>
<a href="javascript:void(0)">
<div class="see-all-requests">
See All Requests
</div>
</a>
</div>
</div>
javascript:
$('*').each(function() { /getting all elements in document
// do something for all elements except the div tag above
});
i want the code to apply for everything except for the div tag and its children, i know i can get all the id's and add an exception , but i want to do that with only the parent tag thanks EDIT:
hi this is exactly what i want to do
$(document.body).find('*:not(#friendRequestMenu):not(#friendRequestMenu *)').each(function () {
var clientWidth = $(window).width();
var clientHeight = $(window).height();
var heightPercent = ($(this).height() / clientHeight) * 100;
var widthPercent = ($(this).width() / clientWidth) * 100;
$(this).css('height', heightPercent.toString());
$(this).css('width', widthPercent.toString());
});
but i want to ignore some elements, as you can see the selector part code isnt working for me
hi i have a div tag with nested divs as shown below
<div class="friendRequestMenu" id="friendRequestMenu">
<div class="toolbarTitle">
<span>Friend Requests</span> <a href="javascript:void(0)" class="hyperlink">Find Friends</a>
</div>
<div id="friendRequestData">
<!-- put div class=requestli to see a block-->
<div class="no-request">
No New Friend Requests
</div>
<a href="javascript:void(0)">
<div class="see-all-requests">
See All Requests
</div>
</a>
</div>
</div>
javascript:
$('*').each(function() { /getting all elements in document
// do something for all elements except the div tag above
});
i want the code to apply for everything except for the div tag and its children, i know i can get all the id's and add an exception , but i want to do that with only the parent tag thanks EDIT:
hi this is exactly what i want to do
$(document.body).find('*:not(#friendRequestMenu):not(#friendRequestMenu *)').each(function () {
var clientWidth = $(window).width();
var clientHeight = $(window).height();
var heightPercent = ($(this).height() / clientHeight) * 100;
var widthPercent = ($(this).width() / clientWidth) * 100;
$(this).css('height', heightPercent.toString());
$(this).css('width', widthPercent.toString());
});
but i want to ignore some elements, as you can see the selector part code isnt working for me
Share Improve this question edited Jul 20, 2011 at 5:21 Yohann asked Jul 19, 2011 at 14:46 YohannYohann 1362 silver badges13 bronze badges 2- If you take out the div tags and their children, then there's nothing left. – Oswald Commented Jul 19, 2011 at 14:49
-
2
I would suggest you reconsider if using the
*
selector is a good idea. Maybe what you want to do is possible without iterating over the zillion elements that make up a production web page? – Jon Commented Jul 19, 2011 at 14:49
3 Answers
Reset to default 5$('*:not(#friendRequestMenu):not(#friendRequestMenu *)').each(...);
Using the :not()
selector should handle this nicely.
The simplest forms are as follows:
$(':not(#friendRequestMenu, #friendRequestMenu *)').each(...);
and
$('*').not('#friendRequestMenu, #friendRequestMenu *');
The second version is likely to be more efficient as I don't believe that the browser's native implementation of querySelectorAll
supports :not(...)
. Don't bother optimizing unless you have an issue with how long the query takes.
Try this
$('*').not("#friendRequestMenu, #friendRequestMenu *").each(function(){
//do something here
});
本文标签: javascriptjquery ignore child elementsStack Overflow
版权声明:本文标题:javascript - jquery ignore child elements - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745485403a2152718.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论