I am trying to pass a parameter from a onClick event using javascript but got a undefined value error, after reading from the questions here at SO and as suggested you need to add and escape the parameter by using \'\ but when applying the solution i am getting the SyntaxError: expected expression, got '}' on execution, Any suggestions would be great!
Here is my actual code.
rootRef.on("child_added", snap => {
var valkey = snap.key;
var name = snap.child("Name").val();
var email = snap.child("Email").val();
$('#table_body').append('<tr><td>'+ name +'</td><td>'+ email +'</td><td><a onClick="deleteMe(' + "'" + valkey + "'" + ')">delete</a></td></tr>');
});
function deleteMe(valkey){
var cKey = valkey;
console.log(cKey);
}
Here is a code snippet similar to my problem.
$(document).ready(function(){
var valkey = "hello!";
$('#table_body').append("<a onClick='deleteMe(\'" + valkey + "\')'>delete</a>");
function deleteMe(valkey){
var cKey = valkey;
console.log(cKey);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="table_body">
</div>