I have a piece of code which looks like the following,
$(document).ready(function(){
var agr1='#19865 - testArg';
var arg2=1856
$('#dv_Test').append('<button onclick="testFunction('+ agr1 +','+ arg2 +')">Test</button>')
});
function testFunction(arg1, arg2) {
alert(arg1);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="dv_Test"></div>
here I am getting error like the following
testFunction(#19865 - testArg,1856)
Uncaught SyntaxError: Invalid or unexpected token
and my string agr1 doesn't have "" with itself
how can I solve this issue?
$('<button />').click(function() { // access scope variables normally})