August 31, 201313 yr Hello thereI am using .slideToggle from here : http://api.jquery.com/slideToggle/And now i got one problem, I made 3 toggle questions/answers , and i used 3 times the same codes with different ID, Class . The code looks like this : <div id="pitanje-1"> <input onclick="return change(this);" type="button" value="+ Šta je to web stranica?" id="dugme1"> <script type="text/javascript"> function change( el ) { if ( document.getElementById("dugme1").value === "+ Šta je to web stranica?" ) document.getElementById("dugme1").value = "- Šta je to web stranica?"; else document.getElementById("dugme1").value = "+ Šta je to web stranica?"; } </script> <p class="pitanje1"><br> This is the paragraph to end all paragraphs. You should feel <em>lucky</em> to have seen such a paragraph in your life. Congratulations! </p> <script> $("#dugme1").click(function () { $("p.pitanje1").slideToggle("slow"); }); </script> </div> <br> <div id="pitanje-2"> <input onclick="return change(this);" type="button" value="+ Šta je web hosting?" id="dugme2"> <script type="text/javascript"> function change( el ) { if ( document.getElementById("dugme2").value === "+ Šta je web hosting?" ) document.getElementById("dugme2").value = "- Šta je web hosting?"; else document.getElementById("dugme2").value = "+ Šta je web hosting?"; } </script> <p class="pitanje2"><br> This is the paragraph to end all paragraphs. You should feel <em>lucky</em> to have seen such a paragraph in your life. Congratulations! </p> <script> $("#dugme2").click(function () { $("p.pitanje2").slideToggle("slow"); }); </script> </div> <br> <div id="pitanje-3"> <input onclick="return change(this);" type="button" value="+ Koji web hosting plan odabrati?" id="dugme3"> <script type="text/javascript"> function change( el ) { if ( document.getElementById("dugme3").value === "+ Koji web hosting plan odabrati?" ) document.getElementById("dugme3").value = "- Koji web hosting plan odabrati?"; else document.getElementById("dugme3").value = "+ Koji web hosting plan odabrati?"; } </script> <p class="pitanje3"><br> This is the paragraph to end all paragraphs. You should feel <em>lucky</em> to have seen such a paragraph in your life. Congratulations! </p> <script> $("#dugme3").click(function () { $("p.pitanje3").slideToggle("slow"); }); </script> </div> Now the problem is , The text " + Koji web hosting plan odabrati? " will change always + and - after click it. But when i click on first question or second , again the + and - will be changed on this question " + Koji web hosting plan odabrati? "So the script :<script type="text/javascript"> function change( el ) { if ( document.getElementById("dugme3").value === "+ Koji web hosting plan odabrati?" ) document.getElementById("dugme3").value = "- Koji web hosting plan odabrati?"; else document.getElementById("dugme3").value = "+ Koji web hosting plan odabrati?"; } </script> is working only for one question , and i used it 3 times on 3 different questions with different ID and CLASSES ...I hope you understand me , what could i do to fix it ?
August 31, 201313 yr Author I fixed the problem with using another codes , but now i need to fix one more thing > Well i made few questions which should toggle the answer after click the button , and its working perfectly , but my problem is . When i open the page the answer is already toggled and hwne i press the button it will be hiden. I want it first to be hiden and after click to toggle and be shown.I am using this codes : <div id="pitanje-1"> <div> <button class="dugme1">+ Šta je to web stranica?</button> </div> <script> $(document).ready(function(){ $("button.dugme1").click(function(){ $("#pitanje-1").toggleClass("maximize"); $(this).html($(this).html() == "+ Šta je to web stranica?" ? "- Šta je to web stranica?" : "+ Šta je to web stranica?"); }); }); </script> <p class="pitanje1"><br> This is the paragraph to end all paragraphs. You should feel <em>lucky</em> to have seen such a paragraph in your life. Congratulations! </p> <script> $("button.dugme1").click(function () { $("p.pitanje1").slideToggle("slow"); }); </script> </div> Edited August 31, 201313 yr by Elvedin
Create an account or sign in to comment