What is the difference between $(“*”, $(“#container1”)) and $(“#container2”).find(“*”)?

后端 未结 2 1611
花落未央
花落未央 2021-01-25 10:50

What is the difference between $(\"*\", $(\"#container1\")) and $(\"#container2\").find(\"*\")?. I usually use AA, but not well in that case can be mo

相关标签:
2条回答
  • 2021-01-25 11:38

    When used properly, the context selector is no different from find. Resig has stated that he dislikes the context selector and would prefer people use .find(), since it makes more sense semantically.

    There's a lot of ways to screw up context; for example, passing a string does not work and causes the selector to default to parsing the entire document. I'm fairly sure your example is using the context correctly (no time to test), but again, using .find() beats this uncertainty.

    0 讨论(0)
  • 2021-01-25 11:39

    I believe the context selector must implicitly call find() itself.

    Best to just use find() for simplicity.

    EDIT: source code from 1.3.2:

    // HANDLE: $(expr, [context])
    // (which is just equivalent to: $(content).find(expr)
    
    0 讨论(0)
提交回复
热议问题