I have a variable,
You can't, you'll have to do something like
You can also load it with AJAX
rhino is right, the snippet lacks of a type for the sake of brevity.
Also, note that if
$php_var has quotes, it will break your script. You shall use addslashes, htmlentities or a custom function.
I'm not sure how necessary this is, and it adds a call to
<span class="metadata" id="metadata-size-of-widget" title="<?php echo json_encode($size_of_widget) ?>"></span>
var size_of_widget = document.getElementById("metadata-size-of-widget").title;
©2020 All rights reserved.