is it possible to achive similiar results in JavaScript ? My aim is to not write static html within string literals.
<?php
if (someCondition) {
?>
I'm here, because PHP allows it.
<?php
}
?>
For example:
<script>
if (someCondition) {
</script>
I'm here, because JavaScript allows it.
<script>
}
</script>
I am aware of the following solution:
<p id = "variable">I'm here, because JavaScript allows it.</p>
<script>
var p = document.getElementById('variable');
if (!someCondition) {
p.parentNode.removeChild(p);
}
</script>
scripttags are executed as a JavaScript Program, and the contents of those will throw syntax errors becauseif(someCondition) {is not a valid program.document.write.