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 :

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

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.


0 comments:

Post a Comment