- 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 escape square brackets in jQuery selector?
To escape square brackets in jQuery selectors is quite easy. Let’s see with an example of escaping the brackets in the name of the <select> box.
Example
Whatever you will select, will get added to the textarea on button click.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function() { $("#addnow").click(function () { $("#myselect :selected").each(function () { $("#text").val($("#text").val() + $(this).text() + "
"); }); }); }); </script> </head> <body> <select name="selectemail[]" multiple="true" id="myselect"> <option value="email">email@example.com</option> <option value="name">David</option> </select> <textarea id="text"></textarea> <button id="addnow">Select and Click to Add</button> </body> </html>
- Related Articles
- How to use universal (*) selector in jQuery?
- JavaScript RegExp return values between various square brackets? How to get value brackets?
- How to use *= operator in jQuery attribute selector?
- How to combine a class selector and an attribute selector with jQuery?
- jQuery :button Selector
- jQuery :checkbox Selector
- jQuery :checked Selector
- jQuery :contains() Selector
- jQuery :disabled Selector
- jQuery :empty Selector
- jQuery :enabled Selector
- jQuery :even Selector
- jQuery :file Selector
- jQuery :first Selector
- jQuery :focus Selector

Advertisements