Jason
Jason

Reputation: 109

jQuery animating div inside php echo

<li>
    <a id="collection" href="collections.php">
        <span class="glyphicon glyphicon-th white"> Collections</span>
    </a>
</li>

<?php include "pagination.php" ?>

<script>
    $("#collection").click(function(){
        // i want to animate the outmost container like this, but this wont work.
        var cont = $("cont");
        cont.animate({height: '300px', opacity: '0.4'}, "slow");
        cont.animate({width: '300px', opacity: '0.8'}, "slow");
        //
    });
</script>

This is my pagination.php, which gives some echoes output :

 <?
if($result) {
        echo '<div class="containerCollection" id="cont">';
        while($row = mysqli_fetch_array ($result)) {    
            echo '<div style="float:left" class="divEntry">';
            echo "<div align='center' class='nameEntry'>".$row['name']."</div>";
            echo '<div align="center"><img src="'.$row['image'].'" class="imageEntry"/></div>'; 
            echo "<div align='center' class='priceEntry'>".$row['price']."</div>";
            echo "<div class='descEntry'>".$row['description']."</div>";
            echo '</div>';
        }
        echo "<div class='text-center' style='clear:both'>";
        echo "<ul class='pagination'>";
        echo $links;
        echo '</ul>';
        echo '</div>';
        echo '</div>';
}}?>

How to call the pagination.php which gives echoes, but only show it when collections button is clicked?

I think this is not ajax since we load the php first and hide it somewhere?

Upvotes: 4

Views: 256

Answers (1)

FLX
FLX

Reputation: 2679

Your cont selector is wrong, it should be $('#cont');

Hide your content div : <div class="containerCollection" id="cont" style="display:none">

Then make it appear in your click function :

      $("#collection").click(function(){
        // i want to animate the outmost container like this, but this wont work.
        var cont = $("#cont");
        cont.show()
            .animate({height: '300px', opacity: '0.4'}, "slow")
            .animate({width: '300px', opacity: '0.8'}, "slow");
        //
      });

(Also your double animate is strange, you should check best practices)

Upvotes: 1

Related Questions