Jquery help

Discussion in 'jQuery' started by DOAD, Apr 5, 2010.

  1. #1
    Hello DP

    I have hit a bit of a problem im working in wordpress inside a loop that reproduces the same code 10 times ( index.php ) on each wordpress post I have the code below which creates a toggled div.
    But when i click the toggle it works on every post rather then just the one... is there any way to avoid this?

    
    			<button>Share this article</button>
                    	<div class="social">whqahadhdfh</div>
    
    HTML:
    Jquery

    <script>
    $("button").click(function () {
    $(".social").slideToggle("slow");
    });
    </script>
     
    DOAD, Apr 5, 2010 IP
  2. zerophean

    zerophean Peon

    Messages:
    91
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Okay, try this one :) :

    <script type="text/javascript">
    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    $("button#s<?php the_ID(); ?>").click(function () {
    $(".social<?php the_ID(); ?>").slideToggle("slow");
    });
    <?php endwhile; endif; ?>
    </script>
    
    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(''); ?>
    <button id="s<?php the_ID(); ?>">Share this article</button>
    <div class="social<?php the_ID(); ?>">whqahadhdfh</div>
    <?php endwhile; endif; ?>
    PHP:
     
    zerophean, Apr 12, 2010 IP
    DOAD likes this.