- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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>
- Related Articles
- How to use OR Operation in jQuery Attribute Selectors?
- How to use jQuery selectors on custom data attributes using HTML5?
- How to use wildcards like $ ('#name*'), $ ('#name%') in jQuery selectors?
- How does CSS Selectors work in jQuery?
- How to use Global Variables in JavaScript?
- How to use Static Variables in JavaScript?
- What are jQuery Selectors?
- How to use CSS Selectors for styling elements?
- How to minimize the use of global variables in JavaScript?
- How to use multiple JavaScript libraries along with jQuery?
- How to Use Static Variables in Arduino?
- How to Use Volatile Variables in Arduino?
- How to Use Environment Variables in Postman?
- How to use global variables in Ruby?
- How to Use Instance Variables in Ruby

Advertisements