CSS styles in JavaScript (setting and getting) – Beau teaches JavaScript



How to set CSS properties and styles in JavaScript. Also how to get CSS.

This video covers style, cssText, setAttribute, and getComputedStyle.

💻 Code: https://codepen.io/beaucarnes/pen/EmVmbZ?editors=1010

🔗 Resource: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Properties_Reference

🐦 Beau Carnes on Twitter: https://twitter.com/carnesbeau

⭐JavaScript Tutorials Playlists⭐
▶JavaScript Basics: https://www.youtube.com/playlist?list=PLWKjhJtqVAbk2qRZtWSzCIN38JC_NdhW5
▶Data Structures and Algorithms: https://www.youtube.com/playlist?list=PLWKjhJtqVAbkso-IbgiiP48n-O-JQA9PJ
▶Design Patterns: https://www.youtube.com/playlist?list=PLWKjhJtqVAbnZtkAI3BqcYxKnfWn_C704
▶ES6: https://www.youtube.com/playlist?list=PLWKjhJtqVAbljtmmeS0c-CEl2LdE-eR_F
▶Clean Code: https://www.youtube.com/playlist?list=PLWKjhJtqVAbkK24EaPurzMq0-kw5U9pJh


We’re busy people who learn to code, then practice by building projects for nonprofits. Learn Full-stack JavaScript, build a portfolio, and get great references with our open source community.

Join our community at https://freecodecamp.com
Read great tech articles at https://medium.freecodecamp.com

source

This Post Has 12 Comments

  1. Sparsh Gupta

    how can we change the style of ::before and ::after pseuodo elements?

  2. Steffen Hofseth

    Can you make a script that will make a list of computed styles that are not matched with inline styles?

  3. Zack Fair

    Good video…they way he pronounced "attribute" for CSS was throwing me off too

  4. Coub Hub

    freeCodeCamp, what font are you using?

  5. The Turdinator

    I know this is JavaScript, but having to toggle a class is easy using jQuery:

    $('#attribute').css("background", blue);

    That being said, I didn't know about setAttribute and I can't wait to use it. Thanks for the great series on JavaScript!

Leave a Reply