Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

.slideToggle

Featured Replies

Hello there

I 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 ?
  • 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 by Elvedin

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.