How to use wildcards like $ ('#name*'), $ ('#name%') in jQuery selectors?

For getting the id that begins or ends with a particular string in jQuery selectors, you shouldn’t use the wildcards $('#name*'), $('#name%'). Instead use the characters ^and $. The ^ is used is used to get all elements starting with a particular string. The $ is used is used to get all elements ending with a particular string.


You can try to run the following code to learn how to get id beginning and endingwith a particular string.

Live Demo

<!DOCTYPE html>
<script src=""></script>

  $("[id$=new1]").css("background-color", "yellow");
  $("[id^=myid]").css("background-color", "green");


<div id="idnew1" myattr="javasubject">Java</div>
<div id="idnew2" myattr="htmlsubject">HTML</div>

<div id="myid1" myattr="rubysubject">Ruby</div>
<div id="myid2" myattr="cppsubject">C++</div>