Peiris
asked on
CSS ID reconnize
I have list of div tags are generated using a php loop. I id each div tag using "divItem_+(some random number)". My question is is it possible to set a CSS tag for these divs using the starting name if the tags. for example
#divItem*{
//styling
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you're trying to target all of them, then absolutely go with a class per WebDevEM's post.
Beware of using general selectors like * or div or regex: [class^="grid-"]. They are the slowest to render. It won't make much of a difference in a small website with a couple of divs, but the minute you start adding more DOM elements, you'll be asking for trouble. Have a look here for more on CSS preformance:
http://csswizardry.com/2011/09/writing-efficient-css-selectors/
Beware of using general selectors like * or div or regex: [class^="grid-"]. They are the slowest to render. It won't make much of a difference in a small website with a couple of divs, but the minute you start adding more DOM elements, you'll be asking for trouble. Have a look here for more on CSS preformance:
http://csswizardry.com/2011/09/writing-efficient-css-selectors/
I'd suggest adding a class to them all, in addition to the ID, so that you can target anything with that class.
WebDevEM is 100% correct. That is best practice. If you like nightmare maintenance easily broken pages, and looking foolish then by all means explore other options, but not only is this best practice it is no more work than trying something screwy. You are already generating with php so you have one line of code to change, and a simple non-complex and efficient rule to put in the CSS.
Cd&
Open in new window
That way you can useOpen in new window