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
  • 17,468
  • 11
  • 72
  • 107

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,406
  • 4
  • 53
  • 92
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
  • 13,157
  • 12
  • 78
  • 96