attributeValue selector in jQuery with example

  1. The attribute with value selector returns all the elements from the group of elements matching specified attribute value.
  2. Attribute selector can be helpful where one wants to select element on page on basis of attribute value.

Example :

    <title>attribute Selector</title>
    <script type="text/javascript" src=""> 
    <script type="text/javascript">
        $(document).ready(function () {
            $("#myButton").click(function () {
                $("[href = 'world.html']").css({ 'font-family': 'comic sans ms', 'font-size': '28px', 'color': 'Orange' });
    <a href="hello.html">hello</a><br/>
    <a href="world.html">world</a><br/>
    <a href="">99codingexamples</a>
    <button id="myButton" >Click ME</button>

Demo :

In the above example, we have used attribute selector. This selector returns all the elements from the group of elements matching specified attribute value. In above example, it selects the anchor element with matching href attribute value and applies CSS to it.


Post a Comment