I am making a blog sort of website, and when you click on the article header it expands (this works fine). At the bottom of this there is a comment button that expands the comments, im using the same code to do this but its not working. Im new to JQuery so any help would be much appreciated.
JQuery
$(document).ready(function() {
$('.showArticle').hide();
$('.articleTitle').show();
$('.showComments').hide();
$('.commentTitle').show();
$('.articleTitle').click(function() {
$(this).next('.showArticle').slideToggle();
});
$('.commentTitle').click(function() {
$(this).next('.showComments').slideToggle();
});
});
PHP
for($i=0; $i<5; $i++)
{
print "
<a href='#' class='articleTitle'>Article name[+]</a>
<div class='showArticle'>
Article about some stuff
<br>
<a href='#' class='commentTitle'>comments[+]</a>
<div class='showComments'>
Comments go here
</div>
</div>
<br>
<br>
";
}
FULL CODE
<!DOCTYPE html>
<?php
session_start();
print "
<html>
<head>
<title>Blog</title>
<link rel='stylesheet' type='text/css' href='stylesheet.css'>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js' type='text/javascript'></script>
<script type='text/javascript'>
$(document).ready(function(){
$('.showArticle').hide();
$('.articleTitle').show();
$('.showComments').hide();
$('.commentTitle').show();
$('.articleTitle').click(function(){
$(this).next('.showArticle').slideToggle();
});
$('.commentTitle').click(function(){
$(this).next('.showComments').slideToggle();
});
});
</script>
</head>
<body>
<header id='header'>
<div class='innertube'>
<h1>Time to blog </h1>
";
if(!isset($_SESSION['loggedin']))
{
print "You are not signed in";
}
if(isset($_SESSION['loggedin']))
{
print "<p>you are signed in as " . ($_SESSION['name']) . "<p>";
}
print "
</div>
</header>
";
print "
<!--MAIN BODY-->
<div id='wrapper'>
<main>
<div id='content'>
<div class='innertube'>
";
for($i=0; $i<5; $i++)
{
print "
<a href='#' class='articleTitle'>Article name</a>
<div class='showArticle'>
Article about some stuff
<br>
<a href='#' class='commentTitle'>comments[+]</a>
<div class='showComments'>
Comment
</div>
</div>
<br>
<br>
";
}
print "
</div>
</div>
</main>
";
print "
<nav id='nav'>
<div class='innertube'>
<h3>Pages</h3>
";
if(!isset($_SESSION['loggedin']))
{
print" <ul>
<li><a href='#'>Home</a></li>
<li><a href='#'>Sign in</a></li>
<li><a href='#'>Link 3</a></li>
<li><a href='#'>Link 4</a></li>
<li><a href='#'>Link 5</a></li>
</ul>";
}
if(isset($_SESSION['loggedin']))
{
print " <ul>
<li><a href='#'>Home</a></li>
<li><a href='#'>Sign out</a></li>
<li><a href='#'>Link 3</a></li>
<li><a href='#'>Link 4</a></li>
<li><a href=''>Link 5</a></li>
</ul> ";
}
</div>
</nav>
</div>
<footer id='footer'>
<div class='innertube'>
<p>Created by JReilly@14412625</p>
</div>
</footer>
</body>
</html>
";
?>