Hello everyone, I'm encountering an issue with this code where I am trying to display a variable in the content. Take a look at the code below:
I am attempting to show the variable $name in the div #divToToggle upon clicking, but the variable does not seem to be working properly. Regular text displays fine, but the variable does not.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
function toggleAndChangeText() {
$('#divToToggle').toggle();
if ($('#divToToggle').css('display') == 'none') {
$('#aTag').html('Collapsed text mode ►');
}
else {
$('#aTag').html('Expanded text mode ▼');
}
}
</script>
</head>
<body>
<?php
$name = 'sasdsad';
?>
<div>
<a id="aTag" href="javascript:toggleAndChangeText();">
Expanded text mode ▼
</a>
<div id="divToToggle">
<?php echo $name; ?>
</div>
</body>
</html>