Why is jQuery.css() not working for me?












1














I've been struggling with some code and quite seem to get it to work - apologies if this is a silly question, I'm still quite new to JavaScript/jQuery etc.



I'm trying to build a Weather App as part of the Free Code Camp course and have built using simpleWeather.js. I'm now trying to animate a little bit of the page to make it a bit more interactive. I have some code:



$('#drop').on('click', function() {
$('.fa-chevron-circle-down').css('transform', 'rotate(180deg)');
});


I believe this should on a click, rotate the icon 180 degrees but no matter what variations I try, I can't seem to get it to work. After spending hours yesterday playing with it I decided it's time to ask for help! (The idea is that once it works, I'll animate the elements below so they only show when the button is clicked).



My codepen is https://codepen.io/woftis/pen/VjppYM



Thanks in advance for any help anyone can give.










share|improve this question



























    1














    I've been struggling with some code and quite seem to get it to work - apologies if this is a silly question, I'm still quite new to JavaScript/jQuery etc.



    I'm trying to build a Weather App as part of the Free Code Camp course and have built using simpleWeather.js. I'm now trying to animate a little bit of the page to make it a bit more interactive. I have some code:



    $('#drop').on('click', function() {
    $('.fa-chevron-circle-down').css('transform', 'rotate(180deg)');
    });


    I believe this should on a click, rotate the icon 180 degrees but no matter what variations I try, I can't seem to get it to work. After spending hours yesterday playing with it I decided it's time to ask for help! (The idea is that once it works, I'll animate the elements below so they only show when the button is clicked).



    My codepen is https://codepen.io/woftis/pen/VjppYM



    Thanks in advance for any help anyone can give.










    share|improve this question

























      1












      1








      1







      I've been struggling with some code and quite seem to get it to work - apologies if this is a silly question, I'm still quite new to JavaScript/jQuery etc.



      I'm trying to build a Weather App as part of the Free Code Camp course and have built using simpleWeather.js. I'm now trying to animate a little bit of the page to make it a bit more interactive. I have some code:



      $('#drop').on('click', function() {
      $('.fa-chevron-circle-down').css('transform', 'rotate(180deg)');
      });


      I believe this should on a click, rotate the icon 180 degrees but no matter what variations I try, I can't seem to get it to work. After spending hours yesterday playing with it I decided it's time to ask for help! (The idea is that once it works, I'll animate the elements below so they only show when the button is clicked).



      My codepen is https://codepen.io/woftis/pen/VjppYM



      Thanks in advance for any help anyone can give.










      share|improve this question













      I've been struggling with some code and quite seem to get it to work - apologies if this is a silly question, I'm still quite new to JavaScript/jQuery etc.



      I'm trying to build a Weather App as part of the Free Code Camp course and have built using simpleWeather.js. I'm now trying to animate a little bit of the page to make it a bit more interactive. I have some code:



      $('#drop').on('click', function() {
      $('.fa-chevron-circle-down').css('transform', 'rotate(180deg)');
      });


      I believe this should on a click, rotate the icon 180 degrees but no matter what variations I try, I can't seem to get it to work. After spending hours yesterday playing with it I decided it's time to ask for help! (The idea is that once it works, I'll animate the elements below so they only show when the button is clicked).



      My codepen is https://codepen.io/woftis/pen/VjppYM



      Thanks in advance for any help anyone can give.







      javascript jquery css






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 29 '16 at 7:32









      StevenWalker

      19715




      19715
























          2 Answers
          2






          active

          oldest

          votes


















          4














          Your #drop element has been created after DOM load i.e. dynamically. Hence you need event delegation here. So attach your click to document and then refer your element - #drop.



          $(document).on('click','#drop', function() {
          $('.fa-chevron-circle-down').css('transform', 'rotate(225deg)');
          });


          Updated PEN



          To be more simpler, since #weather element existed during DOM load, insted of document you can add it to #weather element. Consider below example.



          $('#weather').on('click','#drop', function() {
          $('.fa-chevron-circle-down').css('transform', 'rotate(225deg)');
          });


          and also I believe, it should have been 180deg to be proper turn-around.



          Updated PEN 2 with 180deg and #weather






          share|improve this answer



















          • 1




            Parent element could be $("#weather")...+1
            – Rayon
            Jun 29 '16 at 7:40








          • 1




            Brilliant - thank you :) Will accept once the 10 minutes is up!
            – StevenWalker
            Jun 29 '16 at 7:40






          • 1




            @Rayon.. Was updating the same.. :)
            – Guruprasad Rao
            Jun 29 '16 at 7:42










          • @StevenWalker. .Anytime.. Happy coding.. :)
            – Guruprasad Rao
            Jun 29 '16 at 7:42



















          0














          I was having an issue with jquery .css function with code that's very similar to to OP.



          Problem



          The .css jquery function would not change the css on my .dot-one or .dot-two classes when I clicked button with the #correct-email id.



          Here's the required code examples:





          $(document).on('click', '#correct-email', function () {
          $('.dot-one').css('background-color', '$white');
          $('.dot-two').css('background-color', '$gray-darker');
          ...
          });




          .dot-one {
          background-color: $gray-darker;
          }

          .dot-two {
          background-color: $white;
          }




          Solution



          $(document).on('click', '#correct-email', function () {
          $('.dot-one').css('background-color', '#fff');
          $('.dot-two').css('background-color', '#222');
          ...
          });


          Apparently, jquery doesn't like variables SASS variables being passed into the .css function. I couldn't find that anywhere in the documentation. My assumption is that it'd be able to compute the new value based off of the SASS variable. But it seems all that stuff is pre-processed by sass and not made available to css.



          According to the SASS documentation this is what it sounds like is happening.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38093120%2fwhy-is-jquery-css-not-working-for-me%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            Your #drop element has been created after DOM load i.e. dynamically. Hence you need event delegation here. So attach your click to document and then refer your element - #drop.



            $(document).on('click','#drop', function() {
            $('.fa-chevron-circle-down').css('transform', 'rotate(225deg)');
            });


            Updated PEN



            To be more simpler, since #weather element existed during DOM load, insted of document you can add it to #weather element. Consider below example.



            $('#weather').on('click','#drop', function() {
            $('.fa-chevron-circle-down').css('transform', 'rotate(225deg)');
            });


            and also I believe, it should have been 180deg to be proper turn-around.



            Updated PEN 2 with 180deg and #weather






            share|improve this answer



















            • 1




              Parent element could be $("#weather")...+1
              – Rayon
              Jun 29 '16 at 7:40








            • 1




              Brilliant - thank you :) Will accept once the 10 minutes is up!
              – StevenWalker
              Jun 29 '16 at 7:40






            • 1




              @Rayon.. Was updating the same.. :)
              – Guruprasad Rao
              Jun 29 '16 at 7:42










            • @StevenWalker. .Anytime.. Happy coding.. :)
              – Guruprasad Rao
              Jun 29 '16 at 7:42
















            4














            Your #drop element has been created after DOM load i.e. dynamically. Hence you need event delegation here. So attach your click to document and then refer your element - #drop.



            $(document).on('click','#drop', function() {
            $('.fa-chevron-circle-down').css('transform', 'rotate(225deg)');
            });


            Updated PEN



            To be more simpler, since #weather element existed during DOM load, insted of document you can add it to #weather element. Consider below example.



            $('#weather').on('click','#drop', function() {
            $('.fa-chevron-circle-down').css('transform', 'rotate(225deg)');
            });


            and also I believe, it should have been 180deg to be proper turn-around.



            Updated PEN 2 with 180deg and #weather






            share|improve this answer



















            • 1




              Parent element could be $("#weather")...+1
              – Rayon
              Jun 29 '16 at 7:40








            • 1




              Brilliant - thank you :) Will accept once the 10 minutes is up!
              – StevenWalker
              Jun 29 '16 at 7:40






            • 1




              @Rayon.. Was updating the same.. :)
              – Guruprasad Rao
              Jun 29 '16 at 7:42










            • @StevenWalker. .Anytime.. Happy coding.. :)
              – Guruprasad Rao
              Jun 29 '16 at 7:42














            4












            4








            4






            Your #drop element has been created after DOM load i.e. dynamically. Hence you need event delegation here. So attach your click to document and then refer your element - #drop.



            $(document).on('click','#drop', function() {
            $('.fa-chevron-circle-down').css('transform', 'rotate(225deg)');
            });


            Updated PEN



            To be more simpler, since #weather element existed during DOM load, insted of document you can add it to #weather element. Consider below example.



            $('#weather').on('click','#drop', function() {
            $('.fa-chevron-circle-down').css('transform', 'rotate(225deg)');
            });


            and also I believe, it should have been 180deg to be proper turn-around.



            Updated PEN 2 with 180deg and #weather






            share|improve this answer














            Your #drop element has been created after DOM load i.e. dynamically. Hence you need event delegation here. So attach your click to document and then refer your element - #drop.



            $(document).on('click','#drop', function() {
            $('.fa-chevron-circle-down').css('transform', 'rotate(225deg)');
            });


            Updated PEN



            To be more simpler, since #weather element existed during DOM load, insted of document you can add it to #weather element. Consider below example.



            $('#weather').on('click','#drop', function() {
            $('.fa-chevron-circle-down').css('transform', 'rotate(225deg)');
            });


            and also I believe, it should have been 180deg to be proper turn-around.



            Updated PEN 2 with 180deg and #weather







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jun 29 '16 at 7:41

























            answered Jun 29 '16 at 7:36









            Guruprasad Rao

            24k858123




            24k858123








            • 1




              Parent element could be $("#weather")...+1
              – Rayon
              Jun 29 '16 at 7:40








            • 1




              Brilliant - thank you :) Will accept once the 10 minutes is up!
              – StevenWalker
              Jun 29 '16 at 7:40






            • 1




              @Rayon.. Was updating the same.. :)
              – Guruprasad Rao
              Jun 29 '16 at 7:42










            • @StevenWalker. .Anytime.. Happy coding.. :)
              – Guruprasad Rao
              Jun 29 '16 at 7:42














            • 1




              Parent element could be $("#weather")...+1
              – Rayon
              Jun 29 '16 at 7:40








            • 1




              Brilliant - thank you :) Will accept once the 10 minutes is up!
              – StevenWalker
              Jun 29 '16 at 7:40






            • 1




              @Rayon.. Was updating the same.. :)
              – Guruprasad Rao
              Jun 29 '16 at 7:42










            • @StevenWalker. .Anytime.. Happy coding.. :)
              – Guruprasad Rao
              Jun 29 '16 at 7:42








            1




            1




            Parent element could be $("#weather")...+1
            – Rayon
            Jun 29 '16 at 7:40






            Parent element could be $("#weather")...+1
            – Rayon
            Jun 29 '16 at 7:40






            1




            1




            Brilliant - thank you :) Will accept once the 10 minutes is up!
            – StevenWalker
            Jun 29 '16 at 7:40




            Brilliant - thank you :) Will accept once the 10 minutes is up!
            – StevenWalker
            Jun 29 '16 at 7:40




            1




            1




            @Rayon.. Was updating the same.. :)
            – Guruprasad Rao
            Jun 29 '16 at 7:42




            @Rayon.. Was updating the same.. :)
            – Guruprasad Rao
            Jun 29 '16 at 7:42












            @StevenWalker. .Anytime.. Happy coding.. :)
            – Guruprasad Rao
            Jun 29 '16 at 7:42




            @StevenWalker. .Anytime.. Happy coding.. :)
            – Guruprasad Rao
            Jun 29 '16 at 7:42













            0














            I was having an issue with jquery .css function with code that's very similar to to OP.



            Problem



            The .css jquery function would not change the css on my .dot-one or .dot-two classes when I clicked button with the #correct-email id.



            Here's the required code examples:





            $(document).on('click', '#correct-email', function () {
            $('.dot-one').css('background-color', '$white');
            $('.dot-two').css('background-color', '$gray-darker');
            ...
            });




            .dot-one {
            background-color: $gray-darker;
            }

            .dot-two {
            background-color: $white;
            }




            Solution



            $(document).on('click', '#correct-email', function () {
            $('.dot-one').css('background-color', '#fff');
            $('.dot-two').css('background-color', '#222');
            ...
            });


            Apparently, jquery doesn't like variables SASS variables being passed into the .css function. I couldn't find that anywhere in the documentation. My assumption is that it'd be able to compute the new value based off of the SASS variable. But it seems all that stuff is pre-processed by sass and not made available to css.



            According to the SASS documentation this is what it sounds like is happening.






            share|improve this answer


























              0














              I was having an issue with jquery .css function with code that's very similar to to OP.



              Problem



              The .css jquery function would not change the css on my .dot-one or .dot-two classes when I clicked button with the #correct-email id.



              Here's the required code examples:





              $(document).on('click', '#correct-email', function () {
              $('.dot-one').css('background-color', '$white');
              $('.dot-two').css('background-color', '$gray-darker');
              ...
              });




              .dot-one {
              background-color: $gray-darker;
              }

              .dot-two {
              background-color: $white;
              }




              Solution



              $(document).on('click', '#correct-email', function () {
              $('.dot-one').css('background-color', '#fff');
              $('.dot-two').css('background-color', '#222');
              ...
              });


              Apparently, jquery doesn't like variables SASS variables being passed into the .css function. I couldn't find that anywhere in the documentation. My assumption is that it'd be able to compute the new value based off of the SASS variable. But it seems all that stuff is pre-processed by sass and not made available to css.



              According to the SASS documentation this is what it sounds like is happening.






              share|improve this answer
























                0












                0








                0






                I was having an issue with jquery .css function with code that's very similar to to OP.



                Problem



                The .css jquery function would not change the css on my .dot-one or .dot-two classes when I clicked button with the #correct-email id.



                Here's the required code examples:





                $(document).on('click', '#correct-email', function () {
                $('.dot-one').css('background-color', '$white');
                $('.dot-two').css('background-color', '$gray-darker');
                ...
                });




                .dot-one {
                background-color: $gray-darker;
                }

                .dot-two {
                background-color: $white;
                }




                Solution



                $(document).on('click', '#correct-email', function () {
                $('.dot-one').css('background-color', '#fff');
                $('.dot-two').css('background-color', '#222');
                ...
                });


                Apparently, jquery doesn't like variables SASS variables being passed into the .css function. I couldn't find that anywhere in the documentation. My assumption is that it'd be able to compute the new value based off of the SASS variable. But it seems all that stuff is pre-processed by sass and not made available to css.



                According to the SASS documentation this is what it sounds like is happening.






                share|improve this answer












                I was having an issue with jquery .css function with code that's very similar to to OP.



                Problem



                The .css jquery function would not change the css on my .dot-one or .dot-two classes when I clicked button with the #correct-email id.



                Here's the required code examples:





                $(document).on('click', '#correct-email', function () {
                $('.dot-one').css('background-color', '$white');
                $('.dot-two').css('background-color', '$gray-darker');
                ...
                });




                .dot-one {
                background-color: $gray-darker;
                }

                .dot-two {
                background-color: $white;
                }




                Solution



                $(document).on('click', '#correct-email', function () {
                $('.dot-one').css('background-color', '#fff');
                $('.dot-two').css('background-color', '#222');
                ...
                });


                Apparently, jquery doesn't like variables SASS variables being passed into the .css function. I couldn't find that anywhere in the documentation. My assumption is that it'd be able to compute the new value based off of the SASS variable. But it seems all that stuff is pre-processed by sass and not made available to css.



                According to the SASS documentation this is what it sounds like is happening.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 at 6:01









                alucinare

                340310




                340310






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38093120%2fwhy-is-jquery-css-not-working-for-me%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                    Alcedinidae

                    Can an atomic nucleus contain both particles and antiparticles? [duplicate]