jquery each function
I have a loop called from a database, each loop has a link that has unique url. I'm using a modal script to load the link in a div, however it will only work with the 1st link. The other links called from the database won't open in the modal. They open in a new window. How can I fix this? I've tried ($('#ajax2').each(function()) but that doesn't work.
Here's the script.
if($totalRows_games>0)
{ ?>
<a id="ajax2" title="Pending Challenge" href="FBaction.php?tid=<?php echo $tid?>" onClick="self.location=this.href; return false">Action</a> <?php }} while ($row_games = mysql_fetch_assoc($games)); ?><? }?>
$('#ajax2').click(function(){
var url = $(this).attr('href'); //get the attribute href
var title = $(this).attr('title'); //get the attribute href
lightbox.alert({
width: '400px',
title: title,
rightButtons: ['Close'],
background: '开发者_运维技巧none',
opened: function(){
$('<span />').load(url).appendTo('#lbContent');
},
buttonClick: function(button){
console.log(button);
}
});
return false;
});
Modify your function and as follows
$('#ajax2').click(function(event){
event.preventDefault();
}
精彩评论