How can I select item with class within a DIV?

前端 未结 5 1951
遥遥无期
遥遥无期 2020-12-07 10:30

I have the following HTML:

5条回答
  •  无人及你
    2020-12-07 11:21

    Try:

    $('#mydiv').find('.myclass');
    

    JS Fiddle demo.

    Or:

    $('.myclass','#mydiv');
    

    JS Fiddle demo.

    Or:

    $('#mydiv .myclass');
    

    JS Fiddle demo.

    References:

    • find().
    • Selector context.

    Good to learn from the find() documentation:

    The .find() and .children() methods are similar, except that the latter only travels a single level down the DOM tree.

提交回复
热议问题