![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 JavaScript variables in jQuery selectors?
It’s quite easy to use JavaScript variables in jQuery selectors.
Example
Let’s seen an example to use JavaScript variables in jQuery to hide an element:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("input").click(function(){ var name = this.name; $("input[name=" + name + "]").hide(); } ); }); </script> </head> <body> <h1>Heading 1</h1> <input type="text" id="bx"/> <input type="button" name="bx" value="one"/><br> <input type="text" id="by"/> <input type="button" name="by" value="two"/> <p>To hide the buttons, click on it.</p> </body> </html>
Advertisements