What CSS selector finds elements based on attribute values, regardless of attribute names?

前端 未结 1 1607
离开以前
离开以前 2021-01-27 19:10

For example, in the elements below, what selector would find everything with a value of \"value2\", regardless of the attribute\'s name?

相关标签:
1条回答
  • 2021-01-27 19:41

    May I suggest having a specific attribute and then searching that specific attribute value?

    HTML

    <div data-name="value1"></div>
    <div data-name="value2"></div>
    <div data-name="value2"></div>
    <div data-name="value1"></div>
    

    CSS

    [data-name^='value2'] {
        background-color:red;
    }
    
    0 讨论(0)
提交回复
热议问题