开发者

How to Limit DOM interaction to an element and its children?

I am building a modular framework 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 initializa开发者_开发百科tion, 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 within the test_module object to be within that DOM scope. I currently am using jQuery's selectors but have the feeling I may need to write my own DOM wrapper or something. Any ideas on this?


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

$(selector, context)

which is really the same as

$(context).find(selector);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜