I have this PHP code, which outputs some headings and an inline jQuery script:
<?php
echo '<h2>Test</h2>';
?>
<div>
<form>
<input type="hidden" name="test">
<div id="placeholder"></div>
<script>
jQuery( document ).ready( function( $ ) {
var testVar = 'Some info from a variable.';
$( '<div id="test-id" class="test-class">' + testVar + ' <a href="/test?test=1">Test?</a></div>' ).insertAfter( $( '#placeholder' ) );
});
</script>
</form>
</div>
<?php
echo '<h2>End of test</h2>';
?>
This inserts a test-id
div with a link inside to after the placeholder
div.
This works locally, but when I test this on a live server, if I view source, I see the line under testVar
has been changed to this, it’s like the PHP or jQuery is stripping the end </a>
tag and closing off the script and form:
$( '<div id="test-id" class="test-class">' + testVar + ' <a href="/test?test=1">Test?</script>
</form>
</div>' ).insertAfter( $( '#placeholder' ) );