How to concatenate variable in a string in jQuery?

jQueryWeb DevelopmentFront End Technology

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

Live Demo

<!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>
raja
Published on 08-Dec-2017 06:38:56
Advertisements