Currently, I am facing an issue with applying a highlighting effect to list items in a menu using a snippet of code. The menu items are just POST and I have created a second step to the menu where I want to apply the same effect to any element with a class of .highlight. However, my current code is not working as expected:
[deleted old code]
I could create a new id (let's say, '#highlighter2) and duplicate the code. But I am wondering if there is a more efficient way to apply the effect to a class instead of ID?
UPDATE (here is my updated code):
The script above DOES work on the first ul. The issue arises with the second ul, which appears via jquery (possibly due to being initially set to hidden). Here is the relevant HTML structure (it might be a bit complex, but note the hidden second div. This could be causing the problem. While the first list works perfectly fine with all the highlights, the second list doesn't respond.)?
//When the DOM is ready:
<script type="text/javascript">
$(document).ready(function() {
$('#foo li, #foo2 li').click(function() {
// perform ajax actions
$(this).siblings('li').removeClass('highlight');
$(this).addClass('highlight');
});
//On click of a link in div:
$('#selectCompany a').click(function() {
//Fade in second box:
//Fetch id from clicked link:
var id = $(this).attr('id');
$.ajax({
type: 'POST',
url: 'getFileInfo.php',
data: {'id': id},
success: function(msg){
//all echoed content from PHP file will be in the 'msg' variable:
$('#selectCompanyUser').html(msg)
$('#selectCompanyUser').fadeIn(400);
}
});
});
});
</script>
<div id="selectCompany" class="panelNormal">
<ul id="foo">
<?
// check if any rows were returned
if (mysql_num_rows($membersresult) > 0) {
// yes
// display them one after another
while($row = mysql_fetch_object($membersresult)) {
echo "<li>"."<a href=\"#\""." id=\"".$row->company."\">".$row->company."</a>"."</li>";
}
}
else {
// no
// show status message
echo "No rows found!";
}
// free up result set memory
mysql_free_result($membersresult);
// close connection
mysql_close($link);
?>
</ul>
</div>
<!-- Second Box: initially hidden with CSS "display: none;" -->
<div id="selectCompanyUser" class="panelNormal" style="display: none;">
<div class="splitter"></div>
</div>