javascript - Jquery removing issue divs still remains -


yesterday coded commentbox in php, html , ajax. ajax part gives me opportunity delete comment without refreshing page. way this, give each , every comment (div) unique id via database. let example in mysql database how comment looks like:

username: blabla<br> comment: haha funny<br> id: 52 

this printed out in html page likes example:

<div class="commentstyle" id="<?php echo $commentid; ?>"> comment have id of 52 <div class="deletecomment">delete comment here!</div> </div> 

and then!

comes ajax part coded this:

$(document).ready(function(){  $(".deletecomment").click(function(){    //getting id of comment   id = $(".deletecomment").attr("id");  $.ajax{  type: 'get', url: 'deletecomment.php', data: "id=" + id, success: function(){   $("#" + id).hide();   }    }  });  }); 

this works fine when deleting first comment. wont let me delete other comments unless refresh page >.<. first comment can deleted without refreshing page, when want delete other comments have refresh page multiple times.

how solve this?

the code in document ready event work first click. in order work, must have on click event registered within tag. example :

<div class="deletecomment" onclick="deleteme(id)">delete comment here!</div> </div>  function deleteme(id) {   $.ajax{            type: 'get',           url: 'deletecomment.php',           data: "id=" + id,           success: function(){                 $("#" + id).hide();             }             }          });   } 

if on click on div not work, can use anchor tag (delete here) instead.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -