I have in my screen a few tables that their id ends with "test": studentsTest, marksTest, classesTest etc.
I want them all to have the same style. Is there a way to define a style for all the objects which thier id ends with the same characters?
Thanks Devora
The id attribute is used to point to a specific style declaration in a style sheet. It is also used by JavaScript to access and manipulate the element with the specific id. The syntax for id is: write a hash character (#), followed by an id name. Then, define the CSS properties within curly braces {}.
A Type ID personality is one of the 160 combination styles identified in the Extended DISC assessment. People with an ID personality type tend to be optimistic, talkative, and goal-oriented, focusing on the big picture. They are likely to have an easy and relaxed manner when speaking.
This is because an id value can be given to only one HTML element, in other words, multiple elements cannot have the same id value on the same page.
To use an ID selector in CSS, you simply write a hashtag (#) followed by the ID of the element. Then put the style properties you want to apply to the element in brackets.
If you are able to change your mark-up, the easiest, and most cross-browser compliant way of acheiving this is to use a 'test' class, for example:
.test {background-color:#FC0;}
<table id="students" class="test">...</table>
<table id="marks" class="test">...</table>
<table id="classes" class="test">...</table>
If you're not able to change the mark-up but you are able to use jQuery you can style IDs that end with 'test' like so:
$(document).ready(function(){
$('table[id$=test]').css('background-color','#FC0');
});
Your final option, if you can't or won't use jQuery (or similar) is to use pure CSS3. This uses the same syntax as above but will only work in the more modern browsers:
table[id$=test] {background-color:#FC0;}
According to W3C it's theoretically possible but only in CSS 3.
E[foo$="bar"] an E element whose "foo" attribute value ends exactly with the string "bar"
However I'd say this is far from teh best way of going about it because it will only work in the latest browsers. I also doubt the performance would be up to much. I'd suggest you give the elements that you need to share a common style a class and then style the class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With