如何选择ID以特定字符串开头和结尾的所有元素?

如何选择ID以特定字符串开头和结尾的所有元素?

问题描述:

如何选择所有< tr> 元素,其 id 部分_ ,结尾为 _dummy

How can I select all <tr> elements where their id begins with section_ and ends with _dummy?

我想选择以下< tr> s:

<tr id="section_5_1_dummy">
    <td>...</td>
</tr>

<tr id="section_5_2_dummy">
    <td>...</td>
</tr>


以下CSS3选择器将执行此操作: p>

The following CSS3 selector will do the job:

tr[id^="section_"][id$="_dummy"] {
    height: 200px;
}

^

$ 表示 id 应以结尾。

id 当应用于(例如)< a> 时,可以用另一个属性,例如 href

id itself can be replaced with another attribute, such as href, when applied to (for example) <a>:

a[href^="http://www.example.com/product_"][href$="/about"] {
    background-color: red;
}