如何在jquery中向html添加变量

Here is my jquery i need to add the my_var inside the text

var my_var = <?php echo($my_var); ?>;
$("#dialog-confirms").html("Your code is myvar, Are you sure to Submit this Form ?");

How can i add the my_var inside the HTML of the #dialog-confirms

So the output should be

Your code is 51, Are you sure to Submit this Form ?

Hey You can do this by changing your jquery code as shown below:

$("#dialog-confirms").html(**"Your code is"+my_var+"**, Are you sure to Submit this Form ?");

If you want to add a variable inside your html. Just add before and after your variable.

So, you shold have

$("#dialog-confirms").html("Your code is "+my_var+", Are you sure to Submit this Form ?");

Use this

var my_var = "<?php echo $my_var; ?>";

$("#dialog-confirms").html("Your code is" + myvar + ", Are you sure to Submit this Form?");

You should use Sulthan's answer, but in the future you will be able to use JavaScript's new template string. It's already available in Chrome and FireFox:

$("#dialog-confirms").html(`Your code is ${myvar}, Are you sure to Submit this Form ?`);
var my_var = <?php echo($my_var); ?>;
$("#dialog-confirms").html("Your code is "+myvar+", Are you sure to Submit this Form ?");

Use the + sign in javascript to append variables to string