Reputation: 11
i have to add dynamic onclick attribute while data adding dynamically.
var jsondata = {
jsonarray : [
{data : '<button onclick="function("param")">submit</button>'}
]
}
$('#id').html(jsondata.jsonarray[i].data);
onclick attribute no binded in html code. if is there any other alternative please provide me. anyone help me on this.
Upvotes: 0
Views: 39
Reputation: 781058
The "
before param
is matching the "
that starts the onclick
attribute, so it's just onclick="function("
. You need to use a different quote around the parameter than you use around the attribute.
var jsondata = {
jsonarray: [{
data: '<button onclick="function(\'param\')">submit</button>'
}]
}
$('#id').html(jsondata.jsonarray[i].data);
Upvotes: 1