Code Monkey home page Code Monkey logo

int-u3l5-23-24-student-exercises's Introduction

Lesson 3.5: DOM Manipulation, Part 2

Overview

This lesson focused on using JavaScript to dynamically modify the style of elements on a webpage. The .style property of JavaScript provides an interface to change or add CSS styling to an element.

.style Property

  • The .style property lets you get or set inline styles of an element.
  • It provides a way to add to or modify CSS styling of a webpage directly through JavaScript.

The general format for using .style is:

    selector.style.cssProperty = "value";

Example: To set the width of an image:

    firstImg.style.width = "400px";

Four Steps for Styling with JS

  • Selector: Choose the HTML element you want to style.
  • .style Property: Used to access the style of the chosen element.
  • CSS Property: Decide which style property you want to change.
  • Value: Set the desired value for that property.

Example: To set a div's background color to purple:

div1.style.backgroundColor = "purple";

Camel Casing in JavaScript

  • CSS properties that have two words are written in camel case when using them in JavaScript.

  • Remove any hyphens and capitalize the first letter of the second word.

    CSS JavaScript
    background-color backgroundColor
    font-size fontSize

Example:

header.style.backgroundColor = "black";
header.style.color = "lightGreen";

Key Takeaways

  • JavaScript provides a powerful tool in the .style property to dynamically adjust styles.
  • Remember to use camel case for CSS properties that are typically hyphenated when using them in JavaScript.

Further Reading

For those interested in diving deeper, consider looking into:

Happy coding! ๐Ÿš€

int-u3l5-23-24-student-exercises's People

Contributors

cn-curriculum avatar cn-mika avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.