I have many problems when I create some web application that can dynamically load content. Because of script in loaded contain does not know where to be placed in document and how many duplicated object will be loaded in one document.
Therefore, I want to create some function for modified find function of jQuery object that will be used by script of loaded document like the following code.
<body> <div id="outer-div" class="interested-style"> <div id="loaded-control-1"> <div class="interested-style"></div> </div> <div id="loaded-control-2"> <div class="interested-style"></div> </div> <div id="loaded-control-3"> <div class="interested-style"></div> </div> </body>
The script of "loaded-control-2" object could has some selector like the below code.
$('.interested-style')
In my example document, the above JavaScript code will return three objects. However, if I have some function for modified find function using the selector in specified area of code. The above script should return only one object that is correct result.
The solution might works like the following code.
var dynamic-script = loadSection('some-section-name');
var modified-jQuery = getModifiedjQuery('loaded-control-2');
(function()
{
eval(dynamic-script);
})(modified-jQuery);
Thanks,
PS.1 If you directly modify jQuery object, another script on this page will use your new jQuery selector engine.