0

I have found this form of selector inside a plugin, can anyone explain it to me?

var container = $(this);
var myDiv = $('div', container);

The idea is to only select the div element, why would it have the container variable as well?

MikO
  • 18,243
  • 12
  • 77
  • 109

2 Answers2

1

It is he context of the selector, it's like doing a .find()

EXAMPLE:

$("#selector", context) = $(context).find("#selector")
Matías Cánepa
  • 5,770
  • 4
  • 57
  • 97
0

This question and answer appears to address your requirements for an explanation. How to get the children of the $(this) selector?. Essentially: The jQuery constructor accepts a 2nd parameter which can be used to override the context of the selection.

Community
  • 1
  • 1
Martlark
  • 14,208
  • 13
  • 83
  • 99