
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Concatenate Variable in a String in jQuery
You can easily concatenate variable in a string in jQuery, using the jQuery html() method. Try to run the following code to learn how to use variable in a string with jQuery −
Example
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(function(){ $("a").click(function(){ var id= $(".id").html(); $('.demo').html("<br><div class='new' id='" + id + "'>Welcome to </div>"); }); }); </script> </head> <body> <div class="wrap"> <a href="#">Click me</a> <div class="demo"></div> <div class="id">Qries</div> </div> </body> </html>
Advertisements