Jquery toggle “variable” div?

Your variables are variables, not strings, so you shouldn't be enclosing them within spaces.

Your variables are variables, not strings, so you shouldn't be enclosing them within spaces: 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(); }); }); Furthermore, you need to echo the $article_id_tmp in the JS: var div_id = ''; 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(); }); }); Additionally, classes are 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: show/hide $('. Show_hide_button').

Click(function () { $(this). Next('. Container').toggle(); }); You can of course, remove the container class, and just use $(this).next().toggle().

So easy, thank you very much! – InTry Sep 12 '11 at 12:29.

To me it looks like you would have to write var div_id = ''; instead of var div_id = '$article_id_tmp'; So that you are actually feeding in the right string. Otherwise div_id will always be the string '$article_id_tmp.

Maybe you need to simplify you markup. Use some classes to mark the show/hide button and some classes to you content container. And the script will be very small and understandable: $('.

Container . Show_hide_button a'). Click(function() { $(this).parent().

Siblings('. Show_hide_container').toggle(); }); Live demo: jsfiddle.net/gYkKz/4.

The JavaScript code needs to have the PHP variable correctly output, as you have already done in the HTML. So you need to change: var div_id = '$article_id_tmp'; to var div_id = ''; This requires that the be output inline as in your question. The JavaScript cannot exist in this form in a separate file.

And as @Matt has answered, the div_id is a variable, and should not be quoted when concatenating together when assigning to the div_id_b and div_id_c variables. The assignment should be: var div_id_b = '. Show_hide_button_' + div_id; var div_id_c = '.

Show_hide_container_' + div_id; And lastly the jQuery selectors do not require quoting, since they are variables already. The existing code will be looking for an element called div_id_b which does not exist. The correct selectors should be $(div_id_b).

Click(...) and $(div_id_c).toggle().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions