takn25 Posted May 1, 2011 Share Posted May 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235275-a-little-help-with-jquery-and-divs/ Share on other sites More sharing options...
prestonwinfrey Posted May 12, 2011 Share Posted May 12, 2011 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); } }); }); }); Quote Link to comment https://forums.phpfreaks.com/topic/235275-a-little-help-with-jquery-and-divs/#findComment-1214478 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.