0

I have an object that I am trying to remove from a cssProperty that is being passed to an element. I have tried several things with no luck and am at a loss.

The object looks like

Object {background-color: "#91eae8"}

and I have tried removing it like

delete this.cssProps.background-color;

delete this.cssProps[background-color];

delete this.cssProps['background-color'];

neither has worked and throws viewModel errors because it doesn't know what I'm doing. I cannot change how the object comes in to have quotes around it or anything similar.

10
  • 3
    Don't you mean delete this.cssProps['background-color'];? Commented May 13, 2016 at 19:03
  • 2
    there is no such operator remove in js use delete Commented May 13, 2016 at 19:04
  • 2
    [...]throws viewModel errors[...] you should be more specific about the error that is thrown at the place where you do the delete this.cssProps['background-color']; Commented May 13, 2016 at 19:06
  • 2
    Are you certain this is what you think it is? Commented May 13, 2016 at 19:08
  • 2
    Well, if you're certain everything is as it should be but it's still not working, something is amiss. Why don't you post non-pseudo, relevant code so people can see what's really going on. Because var obj = { 'background-color' : '#91eae8' }; delete this.obj['background-color']; works just fine. Commented May 13, 2016 at 19:22

1 Answer 1

2

In css there is no such thing as an undefined property. They all have default values. So trying to remove a property doesn't work. Instead you can change the value to a different value to get the behavior you want.

I would try doing one of these

this.style.backgroundColor = "inherit";//background will be the same as it's parent
this.style.backgroundColor = "transparent";//background will show what is behind it
this.style.backgroundColor = "inital"; //sets it to the default value
Sign up to request clarification or add additional context in comments.

1 Comment

For a CSSStyleDeclaration (what I think you are talking about) you have empty properties "", you can make a property empty by calling removeProperty. The difference between an empty and a default value is, that an empty property won't overwrite the property of another matching rule. The properties of a CSSStyleDeclaration are all empty by default.

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.