I am trying to hide the heading "City" when someone clicks on a div. E.g. if you click on the div Victoria, then the heading "City" is hidden only for this div, other divs remain unchanged. If you click on the Toronto div, its “City” heading is hidden and the name of the Victoria div will be displayed. This is similar to my previous question: “How to use the same onclick function several times on a php page?”, But this will not work here. Any solution with javascript, jQuery?

Php Code:
<?php
$link = mysqli_connect("localhost", "root", "", "test");
if($link === false)
{
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "SELECT * FROM sample";
if($result = mysqli_query($link, $sql))
{
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
echo "<div style='border: 2px solid black;'><p class='CityTitle".$row['id']."'>City</p>". $row['UserCity'] ."</p></div></br>";
}
mysqli_free_result($result);
}
else
{
echo "No records matching your query were found.";
}
}
else
{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>
source
share