How to solve duplicate objects in dynamic loading page by using jQuery?

I want to solve duplicate objects in dynamic loading content. Please look at the following source code for easier understand. **Base Page HTML With 1 Dynamic Loading Content** > >
> >
>
> Dynamic Content will be placed inside this. >
>
>
> For script in header of this page, it's very easy to select "general-div" object like the following code. $('#general-div') It's quite easy for select "inner-div" object inside placeholder1. So I can select by using the below code. $('.inner-div') The above code could works perfectly. However, I can't use the above code when there is more than 1 duplicated object in the same document like the following HTML. The above code will return 2 objects that don’t what I want. **Base Page HTML - After load another dynamic loading content** > >
> >
>
> Dynamic Content will be placed inside this. >
>
>
>
> Dynamic Content will be placed inside this. >
>
>
> **Possible Solution 1** I must create specified jQuery object foreach script in dynamic loading content like the following code. // Deep copy for jQuery object. var specfiedjQueryObj = $.extend(true, {}, jQuery); // modify find function in jQuery object. specfiedjQueryObj.fn.find = function(selector) { // by adding placeholder selector before eval result. return new specfiedjQueryObj.fn.old_find('#placeholder1 ' + selector); }; // So, I can select any object in dynamic loading content. (function($) { // This result must be 1 object. $('.div1'); })(temp); Even though, this solution should be work great. But I found that jQuery is a very complex object. I found a lot of errors when I try to use it. Do you have any idea for solving this problem? PS.**PlaceHolder Id is not a fixed Id. So, It's impossible to fixed it in selector rule. Moreover, I do not know exactly amount of element and position (first, last or middle) of it in document. Because of dynamic loading content will be displayed on a lot of page.**
Do you perhaps know the content of the inner-div you need to select? Is it unique? Based on the answer and comments in this and your related question either jQuery is not going to work or we don't understand the business rule and technical requirements you need to meet.

以上就是How to solve duplicate objects in dynamic loading page by using jQuery?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏