Customize html element by its class and id

Viewed 45

I am trying to modify this project to show me some dates with colors, but i dont know how should i edit a specific element, lets say with id="3" what is inside the div with id ="March". Until now in all my atempts i only succeded coloring all divs with id="3". So my question is how do i modify the proprietes of an element with id="3" && id="March"?

2 Answers

To target a div within a div do this:

<div id="3">
    <div id="March"></div>
</div>

#3 #March {
    color: purple;
}

Also try to use reasonable variable names in a camelCase naming convention.

Just use the DOM API for this. In your case:

let march = document.getElementById('March')
let third_of_march = document.getElementById('3')

A small tip: IDs should be unique. The DOM API only returns one element. You should use classes in your use-case. This would make it even more simple.

let every_third_day = document.getElementsByClassName('3')

You can simply iterate over all elements and do whatever you want to do.

Related