0

i want to show hide multiple divs with jquery or javascript. I seached the web but i find codes that must have unique divs like:

<div id="div1">text</div>
<div id="div2">text</div>

and so on, but i want to add the divs in a foreache php function so i can't have multiple IDs, the foreache is a div wrapper. So, my question is how can i do that ?

2
Contributors
15
Replies
16
Views
4 Years
Discussion Span
Last Post by pritaeas
0

Yes, like that, but i doesn't seem to work for me.
Is it because a use it in a .php file ?

0
<div class="main">
    <h1>Liga 1 cu hide</h1>
    <?php 
    $itemlimit = 0;
    foreach ($liga1 as $item) {
        if ($itemlimit == 5) { break; }
    ?>
    <div class="flip">
        <?php if ($item->get_permalink()) echo $item->get_title(); ?>
    </div>
    <div class="panel">
        <?php 
        if ($item->get_permalink()) echo '<a href="' . $item->get_permalink() . '" ">'; 
        echo $item->get_title(); 
        if ($item->get_permalink()) echo '</a>';
        echo $item->get_description(); 
        ?>
    </div>
    <?php 
    echo $item->get_date('j M Y, g:i a');                       
    $itemlimit = $itemlimit + 1;
    }
    ?>
</div>

that is my code with div from the thread you gave me

Edited by pritaeas: Aligned for readability.

0

"Warning: Invalid argument supplied for foreach() in /home/icehdnet/public_html/a/index.php on line 279"

Something wrong with your data, I guess it is empty. It does not output any div's so it can't work. You also copied the wrong Javascript snippet. Mine does not use #, and uses the next() function.

Edited by pritaeas

0

yes, it's empty but i don't think that's the problem because i deleted those lines and still doesn't work

0

You copied the wrong javascript snippet. You need this one:

$(".flip").click(function() {
    $(this).next().slideToggle(500);
});
0

i've tested both of them.. i saw in the other post the jsfiddler it does the work but i don't know why id doesn't in my script...

Updated with your function

Edited by dalilice

0

You forgot something else, this should be it (completely this time):

<script type="text/javascript">
$(document).ready(function(){
  $(".flip").click(function(){
    $(this).next().slideToggle(500);
  });
});
</script>

Without the document ready function the code is executed too soon, and will not work.

0

You Are Legend, I'll post a link to your website as soon it will be ready.
Many Thanks !!

Edited by dalilice

0

Not necessary, but if you want link to DaniWeb. Please consider to mark this question solved (button bottom left).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.