0

Hello guys i have this script:

function getList(){
$.ajax({
   type: "POST",
   url: "listaPogovorki.php",
   success: function(msg){
   $("#listaPogovorki").html(msg);
 }});

}

getList();

with this i call this php script:

<table>
<col id="td1"/>
<col id="td2"/>
<col id="td3"/>
<col id="td4"/>
<tr>
<td >#ID</td>
<td >Pogovorka</td>
<td >Avtor</td>
<td >Izmeni</td>
</tr>
<?php $result = mysql_query("SELECT * FROM $table");

while($row = mysql_fetch_array($result))
  {
  ?>
  <tr>
  <td><?php echo $row['id'];?></td>
  <td><?php echo $row['pogovorka'];?></td>
  <td><?php echo $row['avtor'] ?></td>
  <td><img class="editImage" src="images/icon_pencil.png" width="16px" height="16px" alt="<?php echo $row['id'];?>"></td>
  </tr>
  <?php } 
  mysql_close($con);
  ?>

</table>

now the problem is that the script doesn't recognize the html returned from the php script so i can't make clicking on the images(from php script) to fire some code. For example if i make:

$(".editImage").click .... 

it wont work.

How can i make this work?

4 Answers 4

1

You want to use the live function:

$('.editImage').live('click', ....);

Or use another element as an event delegate.

Sign up to request clarification or add additional context in comments.

Comments

1

The output is not recognised because the html you have returned is not part of the original dom before the script was called.

Have a look at bind or live with jquery

Comments

0

You could place the $(".editImage").click inside the AJAX success callback after updating the DOM with the new HTML or use the .live() method:

$('.editImage').live('click', function() {
    ...
});

Comments

0

This is what the .live function is for - it binds even to elements that don't exist yet.

$(".editImage").live("click", function() {});

http://api.jquery.com/live/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.