Open In App

CSS [attribute$=value] Selector

Last Updated : 20 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The [attribute$=”value”] selector is used to select those elements whose attribute value ends with a specified value “value”. The value need not to be present as separate word. It may be a part of another word or expression but it needs to be present at the end. 

Syntax:

[attribute$="value"] {
    // CSS property
} 

Example 1: In this example, we are using the above-explained property.

html




<!DOCTYPE html>
<html>
   
<head>
    <style>
        [class$="str"] {
            background: green;
            color: white;
        }
 
        h1 {
            color: green;
        }
 
        body {
            text-align: center;
            width: 60%;
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
 
    <!-- All items ending with str are highlighted -->
    <div class="firststr">The first div element.</div>
    <div class="stsecondstr">The second div element.</div>
    <div class="start">The third div element.</div>
    <p class="mystr">This is some text in a paragraph.</p>
</body>
   
</html>


Output:

  

Example 2: 

html




<!DOCTYPE html>
<html>
   
<head>
    <title>
        CSS [attribute$=value] Selector
    </title>
 
    <style>
        [class$=Geeks] {
            border: 5px solid blue;
        }
    </style>
</head>
 
<body>
    <h2 style="text-align:center">
          [attribute$=value] Selector
      </h2>
 
    <img src=
         class="Geeks for Geeks"
         alt="gfg">
 
    <img src=
         class="Geeks-Geeks"
         alt="geeks">
 
    <img src=
         class="GeeksforGeeks"
         alt="gfg">
</body>
   
</html>


Output:

  

Supported Browsers: The browser supported by [attribute$=value] selector are listed below:

  • Google Chrome 4.0
  • Internet Explorer 7.0
  • Firefox 3.5
  • Safari 3.2
  • Opera 9.6


Previous Article
Next Article

Similar Reads

CSS [attribute=value] Selector
The [attribute=value] selector in CSS is used to select those elements whose attribute value is equal to "value". Syntax: element [attribute = "value"] { // CSS Property } Note: &lt;!DOCTYPE&gt; must be declared for IE8 and earlier versions. Example 1: In this example, The selector h1[id="geeks"] targets the h1 element with id="geeks" and applies a
1 min read
CSS [attribute*=value] Selector
The [attribute*="str"] selector is used to select those elements whose attribute value contains the specified substring str. This sub-string could be at the start, end, or in middle of the class. Syntax: element [attribute*="str"] { // CSS Property } Example: In this example, the selected &lt;p&gt; elements with the class containing "for" will have
1 min read
CSS [attribute|=value] Selector
The [attribute|=value] selector is used to select those elements whose attribute value is equal to "value" or whose attribute value started with "value" immediately followed by a hyphen (-). Note: Use &lt;!DOCTYPE&gt; to run [attribute|=value] selector in IE8 or earlier versions. Syntax: [attributeType|=value] { // CSS Property } Example 1: In this
2 min read
CSS [attribute~=value] Selector
The [attribute~="value"] selector is used to select those elements whose attribute value contains a specified word. The "value" must be present in the attribute as a separate word and not as part of the other word i.e. if [title~=Geeks] is specified then all elements with Geeks title get selected. Syntax: [attribute~=value] { // CSS property } Exam
2 min read
CSS [attribute^=value] Selector
The [attribute^=value] selector is used to select those elements whose attribute value begins with a given attribute. Syntax: [attribute^=value] { // CSS Property } Example: In this example, The CSS selector p[class^="for"] targets &lt;p&gt; elements with a class attribute that starts with "for" and applies a green background color and white text c
1 min read
jQuery [attribute!=value] Selector
The jQuery [attribute!=value] selector in jquery is used to select each element that doesn't have the specified attribute and value. Syntax: $("[attribute!='value']")Parameter: attribute: This parameter is required to specify the attribute to be searched.value: This parameter is required to specify the value to be searched.Example 1: C/C++ Code
1 min read
jQuery [attribute*=value] Selector
jQuery ("[attribute*=value]") Selector is used to select all elements with attribute specified by attribute parameter that contains the word specified by the value parameter. Syntax: $("[attribute*='value']")Parameters: This selector has two parameters. attribute: attribute specifies the attributes that need to find.value: value is the string that
2 min read
jQuery [attribute$=value] Selector
The jQuery [attribute$=value] selector is used to select each element with a specific attribute, with a specific ending string. Syntax: $("[attribute$='value']")Parameter: attribute: This parameter is required to specify the attribute to find.value: This parameter is required to specify the string i.e. the value should end with.Example 1: C/C++ Cod
1 min read
jQuery [attribute|=value] Selector
The jQuery [attribute|=value] selector is used to select each element with a specific attribute, with a specific string value (like "geeks") or starting string followed by a hyphen (like "geeks-forgeeks"). Syntax: $("[attribute|='value']")Parameter: attribute : This parameter is required to specify the attribute to be searched.value : This paramete
1 min read
jQuery | [attribute=value] Selector
The jQuery [attribute=value] selector is used to select and modify HTML elements with specified attribute and value. Parameter Values: attribute: Used to specify attribute to find. Value: Used to specify value to find. Syntax: $("[attribute=value]") Example-1: This example selects the elements having id GFG and adds a border to it. &lt;!DOCTYPE htm
1 min read