You cannot use same ID
's for multiple elements. Use class
instead:
Change your script to :
$(document).ready(function(){
$("a.aTag").on("click", function(){
var toggleElement = $(this).closest("div").find(".divToToggle");
toggleElement.toggle();
if (toggleElement.css('display') == 'none') {
$(this).html('Collapsed text mode ►');
}
else {
$(this).html('Expanded text mode ▼');
}
});
});
And your PHP code to this:
<?php
$stmt = $DB_con->prepare("SELECT * FROM `topic` ORDER BY id");
$stmt->execute();
foreach ($stmt->fetchAll() as $row) {
echo"
<div class='Post'>
<div class='rgt Pimg'><a href='post.php?id=".$row['id']."'><img src='".$row['e_title']."' class='Pimg'/></a></div>
<div>
<a class='aTag' href='javascript:toggleAndChangeText()'>
Show Content
</a>
<div class='divToToggle'>".$row['e_content']."</div>
</div>
";
}
?>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…