What is the next decimal in $ ('. Elem', elem)?

I use code like $('.elem',elem) , $('.elem',elem).tabs() .

$(".elem") used to select items with this class.

But what's next after the decimal point? What is the use of this?

+6
source share
3 answers

$('.elem',elem) $(elem).find('.elem') . In fact, this is what jQuery does with it under the covers. It finds all elements with class "elem" that are descendants of the elem element.

This is described in the API documentation . It’s worth spending an hour just reading it from start to finish. It has all kinds of useful things that are not known. :-) (I'm not saying that this is one of them [I am not a fan of this myself, some people], just, as a rule, there are a lot of useful things there.)

+11
source

This is the context in which the search is performed.

This is the same as

 $(elem).find('.elem') 

Look here

+4
source

The second parameter passed to jQuery defines the scope or context of the first selector.

It tells jQuery to find all elements with class elem inside the element specified in the second parameter. Elements with a class .elem outside of elem will not be selected.

Given the following HTML:

 <div id="included"> <input/> <input/> </div> <div id="excluded"> <input/> <input/> </div> 

These selectors produce the following output:

 console.log($("input", "#included").length); //2 only those inside included console.log($("input").length); //4 all inputs 

Working example: http://jsfiddle.net/LE6eE/

0
source

Source: https://habr.com/ru/post/946655/


All Articles