在以下代码中:
$(document).ready( function () {
    var hideInit = function () {
            $(selector1).hide();
    }
    var loadInit = function () {
            //get data
            var thingo = $('<div />');
            //populate thingo with a bunch of divs matching selector1
            $(selector2).append(thingo);
    }
    loadInit();
    hideInit();
});
我正在解析一些数据并用它填充 DOM loadInit,然后我希望.hide刚刚创建的 DOM 中存在的每个元素都匹配selector1。
不幸的是,这些元素没有被隐藏——我在这里做错了什么?
谢谢!
解决方案
正如许多人所建议的那样,我的选择器并不正确,但这是我调用函数的顺序。为了保证hideInitrun afterloadInit已经完成,我把它叫做in the end, inside, of loadInit.
$(document).ready( function () {
    var hideInit = function () {
            $(selector1).hide();
    }
    var loadInit = function () {
            //get data
            var thingo = $('<div />');
            //populate thingo with a bunch of divs matching selector1
            $(selector2).append(thingo);
            hideInit();
    }
    loadInit();
});
感谢您的评论/回答!