You’re missing quotes around the content of innerHTML.
If correctoutput is <div></div>
, then you’re script looks like this:
$('#correcto').innerHTML(<div></div>);
Which is invalid, because you’re missing quotes. innerHTML needs a string, which is in quotes in JavaScript. That first <
is where your error is coming from. So you need to do this:
$('#correcto').innerHTML('<?php the_field('correctoutput'); ?>');
Which would create:
$('#correcto').innerHTML('<div></div>');
json_encode
doesn’t cause the error because the result is a valid JavaScript type, which <div></div>
, sans quotes, isn’t.