jquery忽略子元素

Yoh*_*ann 4 html javascript jquery dom

嗨,我有一个嵌套div的div标签,如下所示

<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>
Run Code Online (Sandbox Code Playgroud)

JavaScript的:

$('*').each(function() {   /getting all elements in document
  // do something for all elements except the div tag above
});
Run Code Online (Sandbox Code Playgroud)

我希望代码适用于除div标签及其子代之外的所有内容,我知道我可以获取所有id并添加异常,但我想只使用父标记这样做,谢谢编辑:

嗨,这正是我想要做的

$(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());


    });
Run Code Online (Sandbox Code Playgroud)

但我想忽略一些元素,因为你可以看到选择器部分代码不适合我

Bra*_*tie 5

$('*:not(#friendRequestMenu):not(#friendRequestMenu *)').each(...);
Run Code Online (Sandbox Code Playgroud)

使用:not()选择器应该很好地处理这个.