0

I am trying to make one array equal another array like so: elementStyle[property] = styles[property];

But i keep getting a "invalid argument" error.

Any Ideas????

Addtional:

The code is on: http://prototypejs.org/assets/2009/8/31/prototype.js. The area that i'm interested in is:

setStyle: function(element, styles) {
  element = $(element);
  var elementStyle = element.style, match;
  if (Object.isString(styles)) {
    element.style.cssText += ';' + styles;
    return styles.include('opacity') ?
      element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;
  }
  for (var property in styles)
    if (property == 'opacity') element.setOpacity(styles[property]);
    else
      elementStyle[(property == 'float' || property == 'cssFloat') ?
        (Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
          property] = styles[property];

  return element;
},

This code is fine in Firefox and Chrome, but not in IE. I get an invalid argument error.

7
  • 2
    Can you post the code? There are many possible options, and without seeing the code, you may never get the correct answer. Commented Jul 9, 2010 at 15:52
  • Where does property come from? Commented Jul 9, 2010 at 15:52
  • By all convention, as long as you have elements in your objects/arrays with the key/name of whatever is in property it should work. We'd need to see more code, but I imagine elementStyle or styles is either undefined or doesn't exist. Commented Jul 9, 2010 at 15:54
  • 1
    Please show some actual code. Commented Jul 9, 2010 at 16:01
  • 1
    maybe you mean to say elementStyle['property'] = styles['property'] Commented Jul 9, 2010 at 16:02

2 Answers 2

4

Correct me if I'm wrong, but if you pass in an Object like an Array to styles, the for(var property in styles) will return functions and the conditions do not check for that.

You'll want to put in a check after your for:

for (var property in styles)
   if (typeof property == "string") // should filter out functions/objects/etc.

I'm not sure if this is what the cause of your error is though. I'm not sure what happens if you try assigning a function to the element.style.

Sign up to request clarification or add additional context in comments.

Comments

0

el.style property is an object, not an Array... by the way in webkit it's not enumerable... If you try to iterate over style propertyes try it with a fixed list.

props = ('backgroundColor borderBottomColor borderBottomWidth borderLeftColor borderLeftWidth '+
        'borderRightColor borderRightWidth borderSpacing borderTopColor borderTopWidth bottom color fontSize '+
        'fontWeight height left letterSpacing lineHeight marginBottom marginLeft marginRight marginTop maxHeight '+
        'maxWidth minHeight minWidth opacity outlineColor outlineOffset outlineWidth paddingBottom paddingLeft '+
        'paddingRight paddingTop right textIndent top width wordSpacing zIndex').split(' ');
for (var i=0, len=props.length; i<len; i++) 
        element.style[props[i]] = styles[props[i]];

Another typical bug is that when you want to access border-bottom-width, you must replace /-([a-z])/g to uppercase letters...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.