Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Changing div formatting. In what instances would you use JavaScript?

JavaScript is used in coordination with HTML and CSS. CSS is used obviously for styling your HTML page. As I'm watching the JavaScript Basics video on variables, it is showing me how to change properties of HTML divs using JavaScript and I am left asking myself why I would use this instead of doing it in CSS. Is this just a basic functionality of JavaScript that I will most likely never end up using, or should I remember this, as it will be utilized in the future?

1 Answer

Hi Colton,

You can use that functionality to dynamically change something on the page. For example, lets say there is an option to click on something that says enlarge image. When that click event occurs you could have Javascript change the class of the div which could then be "targeted" by a different css selector to change the size of the image.

Jeff