Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selector with 2 parameters [duplicate]

Tags:

jquery

The following selector $('.sub_menu_container',this) has 2 parameters, the selector you want to search for and a second one. In this case its this. What is the use of adding that second parameter? Ive search the jquery docs but didnt find anything that could help me. Is it some kind of reference?

like image 680
vincent Avatar asked Jan 23 '12 08:01

vincent


3 Answers

the second param provides the context in which to search the element matched by the first selector

like image 61
Rafay Avatar answered Oct 31 '22 13:10

Rafay


its just like :

$(this).find('.sub_menu_container')

its a context re-format of code.

that all :)

like image 22
Royi Namir Avatar answered Oct 31 '22 11:10

Royi Namir


The second parameter scopes the selector, so that it only searches inside the context of the element provided in the second parameter. It is basically the same as saying $(this).find('.sub_menu_container');.

like image 8
Jesper Haug Karsrud Avatar answered Oct 31 '22 12:10

Jesper Haug Karsrud