I have a HTML table, where rows are shown within a while loop.
In each row I have a <td>, and within each of those I place a <img>.
<table>
<tr>
<th class="text-left highlight">presso</th>
</tr>
<?php
while...
?>
<div class="myClass" title="info" style="display: none;">
bla bla bla
</div>
<tr>
<td class="text-left">
<img src="img/i.png" class="myImg" /><?php echo $while_loop_result;?>
</td>
</tr>
<?php
}
?>
</table>
Please notice the class myClass for the div and myImg for the img.
Now, I want to click on the <img> in each table row, and open a jquery dialog which corresponds to that specific row.
<script type="text/javascript">
$(function() {
$('.myClass').dialog(
{
autoOpen: false,
maxWidth:300,
maxHeight: 300,
width: 300,
height: 300,
modal: true,
show: {
effect: "blind",
duration: 1200
},
hide: {
effect: "drop",
duration: 1200
}
}
);
$('.myClass').dialog('close');
$(".myImg").click(
function (e) {
$('.myClass').dialog('open');
});
})
</script>
The script above opens all the dialog windows. If the table has five rows, by clicking on any of the five images, all the five dialog popups open.
How can I open just the one I clicked on?
$('.myClass').click(function(){ $('.'+this)..dialog( { }. You forgot to add click function.