I have result page from DB, on each row I have show/hide button that should show/hide container with $title….
I tried with jquery but it wont work 🙁
<div class="container">
<div class="show_hide_button_<? echo $article_id_tmp; ?>"><a href="#">show/hide</a></div>
<div class="show_hide_container_<? echo $article_id_tmp; ?>">
</div>
</div>
<script type="text/javascript">
var div_id = '$article_id_tmp';
div_id_b+='.show_hide_button_'+ 'div_id';
div_id_c+='.show_hide_container_'+ 'div_id';
$(function(){
$('div_id_b').click(function(){
$('div_id_c').toggle();
});
});
thank you
Your variables are variables, not strings, so you shouldn’t be enclosing them within spaces:
Furthermore, you need to
echothe$article_id_tmpin the JS:Additionally,
classesare usually used to group similar elements on a page; however you’re assigning different classes to every element. For consistency, you might want to consider using an “id” instead of a class, or more preferably, something like the following:You can of course, remove the
containerclass, and just use$(this).next().toggle()