I just learned that an object can have only one ID, so I’m not sure as to how I should continue with this.
How can I, for example assign a css class to ALL divs that share a certain attribute (cannot be ID as I need that tag for something else) except the DIV that I specify? I could maybe do this by removing this specific ID from the div I don’t want to change and then add the class to all those DIVS with that “id”… However I still don’t know how I can identify these divs when I need to use the ID tag for something else.
Thank you 🙂
The reason why I want this:
I have 5 buttons;
When I click one all 4 other DIVS that contain the other buttons will become disabled except this one DIV with this button. I did not want each button to have a function such as:
Button 1 {
disable1
disable2
disable3
disable 4
} for each…
but rather
Button 1 {
Make itself VARIABLE 2
Disable all VARIABLE 1
}
Hope that clears up everything 🙂
Thanks for your answers everyone, all of them solved what I wanted to know 🙂
Not only can an object (element) have only one id, but also an id can be assigned to only one element. So you cannot give all those divs the same id.
You can use the
classattribute. This is meant for this purpose since elements can have multiple classes and multiple elements are allowed to share the same class or classes.Then use the class selector (using
.instead of#):Alternatively, you can use a selector that includes all the ids, like this: