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 971027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:53:50+00:00 2026-05-16T02:53:50+00:00

From my understanding Sizzle returns an array of objects (DOMElements), I am trying to

  • 0

From my understanding Sizzle returns an array of objects (DOMElements), I am trying to walk that array of objects in a for loop but I am getting errors. When I try to get a property with the

obj[index-number]["property"]

it works fine, but when I try to access it after passing it to another function

obj[index-number][arguments[index-number]]

I am getting a return of undefined. I have tried many different ways, including eval to parse the dot notation to no avail. I am stumped. Any pointers or ideas would be awesome. Also, I have verified all input to the function is correct (through alerting them out), also, hard coding the values to get what I want in the function works as well. Here is my code: (sorry it’s lengthy)…..

var ecmafw = function() {
    // Creates the new instance of the object.

    // Sets up the objects global properties:
        this.error = false;

    // Checks to see if arguments were supplied, if none are then it returns false.
    if (arguments.lenght == 0) {
        this.error = "No arguments were supplied.";
        return false;
    }

    // Gives a reference to the result set.
    this.results = Sizzle(arguments[0]);

    this.attr = function() {
        /* Purpose: To add/remove/update an attribute from the results set.
         *
         * Can be used in two ways:
         *      1: .attr("attribute1='value' attribute2='value' attribute3='value'") // adds/removes them all. [negate value to be removed with "-" (used for class)]
         *      2: .attr("attribute", "value") // adds the one. [negate value to be removed with "-" (used for class)]
         *      3: .attr("attribute") // removes the one.
         *      4: .attr("attribute1 attribute2 attribute3") // removes them all.
        */ 

        var len = this.results.length;
        switch (arguments.length) {
            case 1:
                for (var a=0; a < len; a++) {
                    var re = new RegExp("=", "g");
                    if (re.test(arguments[0])) {
                        // Provided a list of attributes to update/create.
                        valuePairs = arguments[0].split("' ");

                        for (var i=0; i < valuePairs.length; i++) {
                            var attributeValue = valuePairs[i].split("=");
                            var newRE = new RegExp(/^-/);
                            var value = attributeValue[1].replace(/'/g, "");

                            if (newRE.test(value)) {
                                this.removeAttr(attributeValue[0], a, value);
                            } else {
                                this.setAttr(attributeValue[0], value, a);
                            }
                        }
                    } else {
                        var attributeSplit = arguments[0].split(" ");
                        if (attributeSplit.length == 1) {
                            // Provided a single attributes to remove.
                            this.removeAttr(arguments[0], a);
                        } else {
                            // Provided multiple attributes to remove.
                            for (var i=0; i < attributeSplit.length; i++) {
                                this.removeAttr(attributeSplit[i], a);
                            }
                        }
                    }
                }
                break;
            case 2:
                // Provided a single name/value pair to update.
                for (var a=0; a < len; a++) {
                    this.setAttr(arguments[0], arguments[1], a)
                }
                break;
            default:
                // Either 0 or more than 2 arguments were supplied.
                this.error = "There were no arguments supplied with the attr() function, or there were too many supplied.";
                return false
                break;
        }
    };

    this.setAttr = function() {
        // Counters for IE className
        if (document.all && !window.opera) {
            arguments[0] = arguments[0].replace(/class/gi, "className");
        }
        if (arguments[0] == "class" || arguments[0] == "className") {
            if (this.results[arguments[2]][arguments[0]] != undefined) {
                arguments[1] += " " + this.results[arguments[2]][arguments[0]]; // Failing
            }
        }
        if (this.results[arguments[2]].setAttribute) {
            this.results[arguments[2]].setAttribute(arguments[0], arguments[1]);
        } else {
            this.results[arguments[2]][arguments[0]] = arguments[1];
        }
    };

    this.removeAttr = function() {
        arguments[0] = arguments[0].replace(/class/gi, "className");
        var item = this.results[arguments[1]];

        if (arguments[0] == "className") {
            arguments[2] = arguments[2].replace("-", "");
            var replaceRE = new RegExp(arguments[2], "gi");

            // For some reason it would find it like this, This is fine but it is not working
            // in Opera. Opera is failing to convert item[eachItem] to an object. (so it says in its error log)
            for (var eachItem in item) { 
                if (arguments[0] == eachItem) {
                    item[eachItem]  = item[eachItem].replace(replaceRE, " ");
                    item[eachItem]  = item[eachItem].replace(/  /gi, " ");
                    item[eachItem]  = item[eachItem].replace(/^ /gi, "");
                    item[eachItem]  = item[eachItem].replace(/ $/gi, "");
                }
            }
        } else {
            if (this.results[arguments[1]].removeAttribute) {
                this.results[arguments[1]].removeAttribute(arguments[0]);
            } else {
                this.results[arguments[1]][arguments[0]] = "";
            }
        }
    };

    // Returns a reference to itself.
    return this;
}
  • 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-16T02:53:50+00:00Added an answer on May 16, 2026 at 2:53 am

    Not sure if this might be the problem, but in the removeAttr function you are accessing the 3rd argument passed in on this line:

    arguments[2] = arguments[2].replace("-", "");
    

    However, in 2 of the 3 calls to this function you only pass in 2 arguments. If the above line runs in either of those cases arguments[2] would be undefined and calling replace("-", "") on it would throw an error.

    Also, you have a typo in your initial arguments check near the top: arguments.lenght.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My understanding of Hibernate is that as objects are loaded from the DB they
From my understanding, Lua is an embeddable scripting language that can execute methods on
Are there any understanding / maintainability issues that result from code like inVar1 ==
I tried to write generic function that remove the duplicate elements from array. public
I might be mis-understanding here but from my understanding a markdown editor strips out
From my understanding the XMPP protocol is based on an always-on connection where you
From my understanding of the CSS spec, a table above or below a paragraph
I'm using TortoiseHg 0.5 (which includes Mercurial 1.0.2) on Vista64. My understanding from the
From my understanding, TreeMap : 1. Insert O( logN ) 2. Delete O( logN
What platforms is Core Text available on from my understanding it is: iPad 3.2

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.