Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize html element by its class and id

Tags:

html

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"?

like image 209
Florin Baciu Avatar asked May 29 '26 15:05

Florin Baciu


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.

like image 175
berkobienb Avatar answered Jun 01 '26 07:06

berkobienb


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.

like image 40
Citrullin Avatar answered Jun 01 '26 06:06

Citrullin