Home  >  jQuery

jQuery Attribute Starts With Selector

February 26, 2013
jQuery starts with selector works in the way that all the elements which starts with given selector are chosen for a given DOM element in the stack. The properties like val or css etc can be changed.
<script>$('p[id^="ab"]').css('background-color','green');</script>
 
In the above code snippet, p element has been selected. The wildcard ^ is used for starts with selector. The CSS properties are being changed. Find the complete example.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<p id="abcd">ABCD</p>
<p id="cdab">EFGH</p>
<script>$('p[id^="ab"]').css('background-color','green');</script>
</body>
</html>
 
Output

ABCD

EFGH

FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us