JQuery- Attribute Equals | [attribute=value] | Selector Example

jquery attribute equals selector example,jquery attribute equals selector,jquery
Share it:

jquery attribute equals selector example


jquery attribute equals selector:-

jquery attribute equals selector allows us to selects the element whose specified attribute value exactly equals a specific string value.

[attribute=value] 

jquery attribute equals selector example:-


In the following example, we will see how we will select all <input> type with the value of  “colorMe” and change the background color of selected <input> to “light green” using the jquery attribute equals selector.



<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script>
        $(document).ready(function(){
            $("input[value='colorMe']").css('background-color','lightgreen');
        });
    </script>
<body>
<input type="button" value="colorMe">
<input type="button" value="SimpleButton">
<input type="button" value="colorMe">
<input type="button" value="SimpleButton">
<input type="text" value="colorMe">
</body>
</html>


Output:-



jquery attribute equals selector



jquery attribute equals selector example explanation :-

$(“input[value='colorMe']“).css(‘background-color’,’lightgreen’); This line tells jquery to select all <input> type elements that has the value of “colorMe”. Once the selection process is done, this css(‘background-color’,’lightgreen’); function sets the background color to lightgreen to all selected items.


                        Share this article with your friends                         
Share it:

jQuery

Post A Comment:

0 comments: