Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5

Thread: .slideToggle

  1. #1
    Member Elvedin's Avatar
    Join Date
    Jan 2013
    Location
    Bosnia And Herzegowina
    Posts
    78
    Member #
    35009

    .slideToggle

    Hello there

    I am using .slideToggle from here : .slideToggle() | jQuery API Documentation
    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 :

    Code:
    <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 :

    Code:
    <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 ?

  2.  

  3. #2
    Member Elvedin's Avatar
    Join Date
    Jan 2013
    Location
    Bosnia And Herzegowina
    Posts
    78
    Member #
    35009
    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 :

    Code:
    <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>
    

  4. #3
    Senior Member Andrew Yurlov's Avatar
    Join Date
    Apr 2011
    Location
    Portland, OR
    Posts
    1,306
    Member #
    27566
    Liked
    181 times
    On the answer div, put a display:hidden;

    Artificial intelligence is nothing compared to natural stupidity -Someone

    Design is a funny word. Some people think design means how it looks.
    But of course, if you dig deeper, it’s really how it works.
    -Steve Jobs



  5. #4
    Member Elvedin's Avatar
    Join Date
    Jan 2013
    Location
    Bosnia And Herzegowina
    Posts
    78
    Member #
    35009
    Thanks , its working. Problem Solved.

  6. #5
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Did Andrew Yurlov's suggestion solve the problem?
    If so, give him a "like".
    If not, would you share your solution so that it may help others?
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:03 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com