CSS style #elements [1-10]

If I had 5 divs with identifiers "element1", "element2", etc ...., there is a way to create an array of elements with something like:

#elements[1-10]{
 position:relative;
}

I know that you guys probably think that I'm crazy, but I'm dealing with some code that is automatically generated, and I will have to edit the main files of these cms, which I do not want to do if client updates are in the future.

With that said, I will have nothing to manually change identifiers for the class.

+3
source share
5 answers

This works in many modern browsers ... except IE:

<style type="text/css">
  p[id*=elements] {
    color: #F00;
  }
</style>

HTML

<p id="elements1">Elements 1</p>
<p id="elements2">Elements 2</p>
<p id="elements3">Elements 3</p>
<p id="elements4">Elements 4</p>
<p id="elements5">Elements 5</p>

But there - from what I know - in no way limit it.

+4
source

, CSS . jQuery?

+2

, (, class="element"). id class , .

, -

#element1, #element2, #element3 {
    position: relative;
}
+2

CSS, JavaScript ( jQuery.)

Try:

var lb = 1;
var ub = 10;
for (var i = lb; i <= ub; i++)
     $("#element" + i).css(*set your css here*);

http://jquery.com/

, script, -, .

+1

css. .

0
source

Source: https://habr.com/ru/post/1751114/


All Articles