0

If I put a css property in JS variable, and change the variable value, does the property change?

And a little subquestion: what's difference between let and var, and what should I use?

For example:

    let property = document.getElementById("el").style.display;
//  variable's content changed
    property = "block";
//  will the #el's display property change?
    
1
  • Please check this answer. Commented Oct 9, 2021 at 7:04

1 Answer 1

1
    let property = document.getElementById("el").style.display;
//  variable's content changed
    property = "block";
//  will the #el's display property change?
    

No . What is changing is the Javascript variable called property. First of all it takes on the value of the style.display of the element #el and then it is given the value of another string which is 'block'

It is possible to set a property of el but on the 'left hand side' you need to tell JS that is what you want it to do:

document.getElementById("el").style.display = "block";
Sign up to request clarification or add additional context in comments.

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.