- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Example
You can try to run the following code to learn how to get id beginning and endingwith a particular string.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("[id$=new1]").css("background-color", "yellow"); $("[id^=myid]").css("background-color", "green"); }); </script> </head> <body> <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> </body> </html>
Advertisements