I have a situation where I need to pass a string with an apostrophe into it in a javascript function. Then this function takes a string and uses it to search for an element by id in the DOM. As an example, I need to call:
showElement('what's')
function showElement(element_id){
document.getElementById(element_id).style.display = "block";
}
I tried to escape the apostrophe like showElement ("what"), but this does not seem to work. Is this even possible?
source
share