I'm frustrated with this. What I am trying to code is a simple xml reader that allows user to choose which data is shown or hidden.
First this code shows the titles of the xml-file and when user clicks a title, date and time should be shown under the title.
The problem is that no matter which title is clicked, it only shows/hides the date-time of the first title under the first title.
<script type="text/javascript">
function toggle(element) {
document.getElementById(element).style.display =
(document.getElementById(element).style.display == "none") ? "" : "none";
}
</script>
<?php
$doc = simplexml_load_file('data.xml');
if($doc == TRUE){
foreach($doc->channel->item as $child){
$title = $child->title;
echo '<table>';
echo '<tr>';
echo '<td><a href="javascript:toggle(\'shit\')">'.$title.'</a></td></tr>';
echo '<tr id="shit" style="display: none;">';
echo '<td>';
echo date("d.m.Y H:i", strtotime($child->pubDate));
echo '</td></tr>';
echo '</table>';
}
}
?>