views:

33

answers:

1

I am building a modular frame work for a PHP MVC site. I am using Jquery. I have a registerModule('module_name') method that when called creates an instance of a module object with this name. These module objects are functions that return an object they are contained within individual script files

example of test_module.js

core.modoules.test_module = function(sandbox){
  return{
    init : function(){

    }
  };
};

within the registerModule() method I am handling inheritance and initialization. On initialization I would like to check the DOM for an element matching this module. For this example we'd look for a div with id "test_module" and i would like to limit any DOM interaction with in the test_module object to be with in that DOM scope. I currently am using jQuery's selectors but have the feeling I may need to right my own dom wrapper or something. Any ideas on this?

+1  A: 

$() takes a 2nd parameter which limits the search scope

$(selector, context)

which is really the same as

$(context).find(selector);
Scott Evernden