Jump to content

A little help with jquery and divs


takn25

Recommended Posts

Hi,  Ill post the code first.

 


$(function()

{

$('.follow').click(function(){

var name=$(this).attr('name');
var info= 'test=' + name;

$.ajax({  
      type: "GET",  
      url: "yes.php",  
      data: info,  
      success: function(data){  
               $('.test_results').html(data); 

          }  
        });  
  })

})





<body>
<button name='yabadaba' class="follow" > </button>
<div class='test_results'> </div>

<button name='whatsup' class="follow" > </button>
<div class='test_results'> </div>



</body>



 

Ok as you can see there are two buttons and two div classes which are the same except the name difference between the buttons. What I want to achieve when the result comes from PHP I only target the div class below the button and not show the results in all the divs with the class test_result. Any help is appreciated thanks.

 

 

Link to comment
Share on other sites

  • 2 weeks later...

Use jQuery's next() function.

 

Get the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling only if it matches that selector.

 

$(function() {

    $('.follow').click(function() {
    
        var name = $(this).attr('name');
        var info = 'test=' + name;
        var $this = $(this);

        $.ajax({  
            type: "GET",  
            url: "yes.php",  
            data: info,  
            success: function(data) {  
                
                $this.next('.test_results').html(data);  
            }  
        });  
    });    
});

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.