[jQuery] .click stops trigger after clicked once.
Hi,
I'm new to JQuery and have a problem with a .click function that stops
working after it has been clicked once. My page looks similar to this:
<div id="maindiv">
div id="row_1"><a class="expandlink"..></div>
div id="row_2"><a class="expandlink"..></div>
div id="row_3"><a class="expandlink"..></div>
</div> <!-- end maindiv -->
When page is first loaded maindiv is populated by an ajax call. Then
if the user clicks any of the rows the selected row_n div is replaced
with data from another ajax call. If another row has been clicked that
row will be replaced too with an ajax call.
This works if you click a row once, but not the second time. I have a
feeling there is a solution but I can't figure it out. It seems
the .click doesnt trigger the second time.
Any suggestions how I can solve this?
$(document).ready(function() {
lastblock = "";
//load all rows on first page load
$("#maindiv").load("my ajax call..", function() {
//if a link with class expandlink is clicked...
$("a.expandlink").click(function() {
//replace content in lastblock with summarized info
if (lastblock != "" ) {
$("#row_" + lastblock).load("my ajax call w param &shortInfo=" +
lastblock );
}
//replace content in clicked block with full info
$("#row_" + $(this).attr("id")).load("my ajax call w
param&fullInfo=" + $(this).attr("id") );
//set latest block shown
lastblock = $(this).attr("id") ;
});
});
});