Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7247991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:04:45+00:00 2026-05-28T22:04:45+00:00

There is something wrong in my jQuery plugin. I can’t post the whole script

  • 0

There is something wrong in my jQuery plugin. I can’t post the whole script because it would be too big, this is a little and modified excerpt. Basically it works this way:

  1. An ajax call, if result set is empty then backup the element and it’s content (if there is no already backup defined) and the override it’s content
  2. If result set contains data look for certain elements inside it and use .html() to display the data

But there is somehting wrong in the above. When the call is executed 3 consecutive times children of the backup is sadly empty!

Any help is much appreciated. Here is a simplified version of the control flow:

var backup = function() { this.data('backup', this.clone(true)); }

var onObjectProperty = function(obj) {

   // This is where my script fail!!! 3 consecutive times of empty data,
   // and children() contains no data!
   if($.type(this.data('backup')) !== 'undefined')
      console.log(this.data('backup').children());

    };

if(!val.error && !val.count) // Not an error, but data is empty
{
   // Keyword "this" is the current element in selection loop (on which
   // the plugin was invoked)
   if($.type(context.data('backup')) === 'undefined')
      backup.call(this); // Backup if not already defined

   opt.onEmpty.call(context); // Call the function to handle empty data
   return true; // Skip the current iteration in the loop
}

// Here we have no errors and result set contains data
onObjectProperty.call(this, obj); // Pass the context and the data

EDIT: found the error, was not cloning the backup before adding it to the DOM!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:04:46+00:00Added an answer on May 28, 2026 at 10:04 pm

    What’s with the parentheses on the second if-$.type line? =)

    Ok got it. Not sure how to read all these “obj”, “context” and “val”, how they fit in, but for what it’s worth I managed to get backups to/fro data going, see below.

    Cool idea anyway!

    <html>
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script>
    var backup = function() { this.data("backup", this.clone(true)); }
    function doit(x) { if ($.type(x.data("backup")) == "undefined") { backup.call(x); } }
    function dumpit(x) {
        if ($.type(x.data("backup")) != "undefined") {
            console.log("backup", x.data("backup"));
            console.log("children", x.data("backup").children());
        }
    }
    function addit(x) {
        if ($.type(x.data("backup")) != "undefined") {
            var x = x.data("backup").clone();
            x.attr("id",null);
            $("body").append(x);
        }
    }
    </script>
    </head>
    <body>
        <div id="xxx" class="yyy">
            <p class="zzz">helu</p>
            <a href="#">there</a>
            <input></input>
        </div>
        <button onclick="doit($('#xxx'));">do</button>
        <button onclick="dumpit($('#xxx'));">see</button>
        <button onclick="addit($('#xxx'));">add</button>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There's something wrong with my code or I'm just not understanding this fully. I
There is something wrong with this trigger. But what? CREATE TRIGGER MYCOOLTRIGGER AFTER INSERT
at the moment i'm using this validation plugin: ( http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/ ) but when it
Are methods calls really so slow or is there something wrong in my computer?
I wonder if there is something wrong with the copy constructor function below? class
Is there something like InstallShield that I can use for free?
Is there something like Python's getattr() in C#? I would like to create a
Is there something like a panel that I can use in a MFC application.
I'm using current jQuery plugin (address) and I have this code (I'm using SEO
is there something wrong in the code? its not actually updating all textinput but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.