What's the proper syntax for calling a function with a string parameter in an HTML attribute?

I have a few buttons generated in this Javascript method, and one of them has onclick() handler where I need to pass a string as an input parameter.

function ShowButtons() {
  let $previewDiv = $("#ServicesPreview");
  $previewDiv.html("<button id='myBtn' onclick='CheckID('MYID')'></button>")
}

I can't enclose the string in single quotes because it produces this on the website, and I get the error "Unexpected end of input":

<button id="myBtn" onclick="CheckID(" MYID')'></button>

I've also tried no quotes, and I can't use double-quotes because that terminates the string being passed into the jQuery.html method. What's the proper syntax here?



from Recent Questions - Stack Overflow https://ift.tt/3A9jCbl
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations