jQuery - selecting elements from inside a element

前端 未结 7 1581
广开言路
广开言路 2020-12-02 08:19

let\'s say I have a markup like this:

... ... ...

and

7条回答
  •  甜味超标
    2020-12-02 08:49

    ....but $('span', $('#foo')); doesn't work?

    This method is called as providing selector context.

    In this you provide a second argument to the jQuery selector. It can be any css object string just like you would pass for direct selecting or a jQuery element.

    eg.

    $("span",".cont1").css("background", '#F00');
    

    The above line will select all spans within the container having the class named cont1.

    DEMO

提交回复
热议问题