You should wrap all your HTML for a single 'hit' inside a tag so you can refer to it easily, like: <div class="hit" id="id_article"> <a href="#">Hit</a> <span class="hits">484</span> </div>
Then your script could look like this (you can assign click handlers to multiple elements at the same time): $('.hit').click(function(){ var id=this.id var hit = this; $.post('../../posts/hit.php', {id:id}, function (data){ if (data == 1){ $(hit).children('hit_output').text(newvalue); $('#responseSuccess').slideDown(1000).fadeOut(4000); }; }); return false; }); For the response message you could append it to the current hit and use CSS relative positioning. - ricardo On Oct 21, 7:53 am, Brandnew <[EMAIL PROTECTED]> wrote: > Hello, > > Here's what I've made. I have a lot of divs on different pages which > you can Digg (it's called hit). When I click on hit, I've made a code > that send Ajax data to a second page which record everything needed in > the database. That's working easily. But then, I need to add something > to that and I can't. I need to update the number of diggs and add 1 > when task is complete and I need also to add it just in one div. I > also have a little message showing up but that's not necessary for > now. > > Here's my JS script > > $('.hit').each(function(){ > $(this).click(function(){ > var id=this.id; > > $.post('../../posts/hit.php', > {id:id}, function (responseText){ > if (responseText == 1){ > > $ > ('#responseSuccess').slideDown(1000).fadeOut(4000); > > } > }) > return false; > }) > }) > > And here's my code where the html is > > <a class="hit" id="<?php echo $id_article ;?>">Hit</a> > <span style="color:<?php echo $link_color;?>"> > <?php echo ' (<span class="hit_output"><span>' . > $donnees['hit'] . '</span> </span>)';?></span> > > I probably put too much span and stuff but I tried several things. THe > fact is it never updates just the number of diggs (hits) on the actual > div but on all of them. Or when I had a message id="responseText" it > always shows at the same place even if he updates the good id. > > Well, I hope I'm clear. I'm not really good at JS so I just try to > work things out. > > Thanks in advance, > > Ced