0

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.

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.