Jquery What have I done wrong?












0















$(document).ready(function(){
$('.fa').hide();
$('.icon').click (function(){
$('.icon').addClass('active');
if($(".fa").css("display") == "none") {
$(".fa").show();
}
if $('.icon').click && $('.icon').hasCalss('active') (function(){
$(".fa").hide();
});
});
});


I want it so that when you click on a div(in this case '.icon') The div .fa shows but when I click on it again and .fa is showing it hides .fa
In the console it keeps on coming up with these 2 errors




Uncaught SyntaxError: Unexpected identifier SyntaxError: Unexpected
identifier




but I don't know whats wrong as i'm quite new to jquery and java-script.
Help would be appreciated.
Thank you :)










share|improve this question




















  • 3





    .hasCalss( Spelling matters in programming, and if $('.icon') but if statements must be followed by (, etc

    – CertainPerformance
    Nov 24 '18 at 8:33








  • 1





    .hasCalss should be .hasClass

    – Hkachhia
    Nov 24 '18 at 8:34











  • $('.icon').hasClass('active')(function() { ... }) (using a boolean as a function that takes a function) is also... interesting. You should probably take a tutorial/course about JS, and then jQuery.

    – Jeto
    Nov 24 '18 at 8:36













  • Sorry, hasClass is spelled wrong. I have fixed it in the code but it has changed nothing. If you want to look at the protect follow this link. thimbleprojects.org/miniocto/591825

    – Oran
    Nov 24 '18 at 8:38













  • I'd suggest figuring out the basics of JS syntax before trying to get your head around the functions of any particular library

    – CertainPerformance
    Nov 24 '18 at 8:40
















0















$(document).ready(function(){
$('.fa').hide();
$('.icon').click (function(){
$('.icon').addClass('active');
if($(".fa").css("display") == "none") {
$(".fa").show();
}
if $('.icon').click && $('.icon').hasCalss('active') (function(){
$(".fa").hide();
});
});
});


I want it so that when you click on a div(in this case '.icon') The div .fa shows but when I click on it again and .fa is showing it hides .fa
In the console it keeps on coming up with these 2 errors




Uncaught SyntaxError: Unexpected identifier SyntaxError: Unexpected
identifier




but I don't know whats wrong as i'm quite new to jquery and java-script.
Help would be appreciated.
Thank you :)










share|improve this question




















  • 3





    .hasCalss( Spelling matters in programming, and if $('.icon') but if statements must be followed by (, etc

    – CertainPerformance
    Nov 24 '18 at 8:33








  • 1





    .hasCalss should be .hasClass

    – Hkachhia
    Nov 24 '18 at 8:34











  • $('.icon').hasClass('active')(function() { ... }) (using a boolean as a function that takes a function) is also... interesting. You should probably take a tutorial/course about JS, and then jQuery.

    – Jeto
    Nov 24 '18 at 8:36













  • Sorry, hasClass is spelled wrong. I have fixed it in the code but it has changed nothing. If you want to look at the protect follow this link. thimbleprojects.org/miniocto/591825

    – Oran
    Nov 24 '18 at 8:38













  • I'd suggest figuring out the basics of JS syntax before trying to get your head around the functions of any particular library

    – CertainPerformance
    Nov 24 '18 at 8:40














0












0








0








$(document).ready(function(){
$('.fa').hide();
$('.icon').click (function(){
$('.icon').addClass('active');
if($(".fa").css("display") == "none") {
$(".fa").show();
}
if $('.icon').click && $('.icon').hasCalss('active') (function(){
$(".fa").hide();
});
});
});


I want it so that when you click on a div(in this case '.icon') The div .fa shows but when I click on it again and .fa is showing it hides .fa
In the console it keeps on coming up with these 2 errors




Uncaught SyntaxError: Unexpected identifier SyntaxError: Unexpected
identifier




but I don't know whats wrong as i'm quite new to jquery and java-script.
Help would be appreciated.
Thank you :)










share|improve this question
















$(document).ready(function(){
$('.fa').hide();
$('.icon').click (function(){
$('.icon').addClass('active');
if($(".fa").css("display") == "none") {
$(".fa").show();
}
if $('.icon').click && $('.icon').hasCalss('active') (function(){
$(".fa").hide();
});
});
});


I want it so that when you click on a div(in this case '.icon') The div .fa shows but when I click on it again and .fa is showing it hides .fa
In the console it keeps on coming up with these 2 errors




Uncaught SyntaxError: Unexpected identifier SyntaxError: Unexpected
identifier




but I don't know whats wrong as i'm quite new to jquery and java-script.
Help would be appreciated.
Thank you :)







javascript jquery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 9:02









Mustapha Larhrouch

2,6992722




2,6992722










asked Nov 24 '18 at 8:32









OranOran

122




122








  • 3





    .hasCalss( Spelling matters in programming, and if $('.icon') but if statements must be followed by (, etc

    – CertainPerformance
    Nov 24 '18 at 8:33








  • 1





    .hasCalss should be .hasClass

    – Hkachhia
    Nov 24 '18 at 8:34











  • $('.icon').hasClass('active')(function() { ... }) (using a boolean as a function that takes a function) is also... interesting. You should probably take a tutorial/course about JS, and then jQuery.

    – Jeto
    Nov 24 '18 at 8:36













  • Sorry, hasClass is spelled wrong. I have fixed it in the code but it has changed nothing. If you want to look at the protect follow this link. thimbleprojects.org/miniocto/591825

    – Oran
    Nov 24 '18 at 8:38













  • I'd suggest figuring out the basics of JS syntax before trying to get your head around the functions of any particular library

    – CertainPerformance
    Nov 24 '18 at 8:40














  • 3





    .hasCalss( Spelling matters in programming, and if $('.icon') but if statements must be followed by (, etc

    – CertainPerformance
    Nov 24 '18 at 8:33








  • 1





    .hasCalss should be .hasClass

    – Hkachhia
    Nov 24 '18 at 8:34











  • $('.icon').hasClass('active')(function() { ... }) (using a boolean as a function that takes a function) is also... interesting. You should probably take a tutorial/course about JS, and then jQuery.

    – Jeto
    Nov 24 '18 at 8:36













  • Sorry, hasClass is spelled wrong. I have fixed it in the code but it has changed nothing. If you want to look at the protect follow this link. thimbleprojects.org/miniocto/591825

    – Oran
    Nov 24 '18 at 8:38













  • I'd suggest figuring out the basics of JS syntax before trying to get your head around the functions of any particular library

    – CertainPerformance
    Nov 24 '18 at 8:40








3




3





.hasCalss( Spelling matters in programming, and if $('.icon') but if statements must be followed by (, etc

– CertainPerformance
Nov 24 '18 at 8:33







.hasCalss( Spelling matters in programming, and if $('.icon') but if statements must be followed by (, etc

– CertainPerformance
Nov 24 '18 at 8:33






1




1





.hasCalss should be .hasClass

– Hkachhia
Nov 24 '18 at 8:34





.hasCalss should be .hasClass

– Hkachhia
Nov 24 '18 at 8:34













$('.icon').hasClass('active')(function() { ... }) (using a boolean as a function that takes a function) is also... interesting. You should probably take a tutorial/course about JS, and then jQuery.

– Jeto
Nov 24 '18 at 8:36







$('.icon').hasClass('active')(function() { ... }) (using a boolean as a function that takes a function) is also... interesting. You should probably take a tutorial/course about JS, and then jQuery.

– Jeto
Nov 24 '18 at 8:36















Sorry, hasClass is spelled wrong. I have fixed it in the code but it has changed nothing. If you want to look at the protect follow this link. thimbleprojects.org/miniocto/591825

– Oran
Nov 24 '18 at 8:38







Sorry, hasClass is spelled wrong. I have fixed it in the code but it has changed nothing. If you want to look at the protect follow this link. thimbleprojects.org/miniocto/591825

– Oran
Nov 24 '18 at 8:38















I'd suggest figuring out the basics of JS syntax before trying to get your head around the functions of any particular library

– CertainPerformance
Nov 24 '18 at 8:40





I'd suggest figuring out the basics of JS syntax before trying to get your head around the functions of any particular library

– CertainPerformance
Nov 24 '18 at 8:40












2 Answers
2






active

oldest

votes


















0














You need to use toogle function :



$(document).ready(function(){
$('.fa').hide();
$('.icon').click (function(){
$('.icon').addClass('active');
$(".fa").toogle();
});
});


https://www.w3schools.com/jquery/eff_toggle.asp






share|improve this answer
























  • An answer with a typo seems very appropriate here :)

    – Jeto
    Nov 24 '18 at 9:03





















0














If it is just about switching classes on click you can use the .toggleClass()-method:
Link to toggleClass() on http://api.jquery.com.
Just use your CSS-Class to manipulate the state.






$(document).ready(function(){

const icon = $('.icon');

icon.click(function() {
$(this).toggleClass("active");
});


});

.container {
border: 1px solid grey;
padding: 0.5em;
text-align: center;
}

.icon {
opacity: 0.5;
font-size: 48px;
color: #ddd;
transition: all 300ms linear;
cursor: pointer;
}

.icon.active {
opacity: 1;
color: #bada55;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" rel="stylesheet"/>

<section class="container">

<span class="icon active">
<i class="fas fa-stroopwafel"></i>
</span>

<span class="icon">
<i class="fas fa-balance-scale"></i>
</span>

</section>








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%2f53456514%2fjquery-what-have-i-done-wrong%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









    0














    You need to use toogle function :



    $(document).ready(function(){
    $('.fa').hide();
    $('.icon').click (function(){
    $('.icon').addClass('active');
    $(".fa").toogle();
    });
    });


    https://www.w3schools.com/jquery/eff_toggle.asp






    share|improve this answer
























    • An answer with a typo seems very appropriate here :)

      – Jeto
      Nov 24 '18 at 9:03


















    0














    You need to use toogle function :



    $(document).ready(function(){
    $('.fa').hide();
    $('.icon').click (function(){
    $('.icon').addClass('active');
    $(".fa").toogle();
    });
    });


    https://www.w3schools.com/jquery/eff_toggle.asp






    share|improve this answer
























    • An answer with a typo seems very appropriate here :)

      – Jeto
      Nov 24 '18 at 9:03
















    0












    0








    0







    You need to use toogle function :



    $(document).ready(function(){
    $('.fa').hide();
    $('.icon').click (function(){
    $('.icon').addClass('active');
    $(".fa").toogle();
    });
    });


    https://www.w3schools.com/jquery/eff_toggle.asp






    share|improve this answer













    You need to use toogle function :



    $(document).ready(function(){
    $('.fa').hide();
    $('.icon').click (function(){
    $('.icon').addClass('active');
    $(".fa").toogle();
    });
    });


    https://www.w3schools.com/jquery/eff_toggle.asp







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 24 '18 at 9:00









    Mustapha LarhrouchMustapha Larhrouch

    2,6992722




    2,6992722













    • An answer with a typo seems very appropriate here :)

      – Jeto
      Nov 24 '18 at 9:03





















    • An answer with a typo seems very appropriate here :)

      – Jeto
      Nov 24 '18 at 9:03



















    An answer with a typo seems very appropriate here :)

    – Jeto
    Nov 24 '18 at 9:03







    An answer with a typo seems very appropriate here :)

    – Jeto
    Nov 24 '18 at 9:03















    0














    If it is just about switching classes on click you can use the .toggleClass()-method:
    Link to toggleClass() on http://api.jquery.com.
    Just use your CSS-Class to manipulate the state.






    $(document).ready(function(){

    const icon = $('.icon');

    icon.click(function() {
    $(this).toggleClass("active");
    });


    });

    .container {
    border: 1px solid grey;
    padding: 0.5em;
    text-align: center;
    }

    .icon {
    opacity: 0.5;
    font-size: 48px;
    color: #ddd;
    transition: all 300ms linear;
    cursor: pointer;
    }

    .icon.active {
    opacity: 1;
    color: #bada55;
    }

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <link href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" rel="stylesheet"/>

    <section class="container">

    <span class="icon active">
    <i class="fas fa-stroopwafel"></i>
    </span>

    <span class="icon">
    <i class="fas fa-balance-scale"></i>
    </span>

    </section>








    share|improve this answer






























      0














      If it is just about switching classes on click you can use the .toggleClass()-method:
      Link to toggleClass() on http://api.jquery.com.
      Just use your CSS-Class to manipulate the state.






      $(document).ready(function(){

      const icon = $('.icon');

      icon.click(function() {
      $(this).toggleClass("active");
      });


      });

      .container {
      border: 1px solid grey;
      padding: 0.5em;
      text-align: center;
      }

      .icon {
      opacity: 0.5;
      font-size: 48px;
      color: #ddd;
      transition: all 300ms linear;
      cursor: pointer;
      }

      .icon.active {
      opacity: 1;
      color: #bada55;
      }

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <link href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" rel="stylesheet"/>

      <section class="container">

      <span class="icon active">
      <i class="fas fa-stroopwafel"></i>
      </span>

      <span class="icon">
      <i class="fas fa-balance-scale"></i>
      </span>

      </section>








      share|improve this answer




























        0












        0








        0







        If it is just about switching classes on click you can use the .toggleClass()-method:
        Link to toggleClass() on http://api.jquery.com.
        Just use your CSS-Class to manipulate the state.






        $(document).ready(function(){

        const icon = $('.icon');

        icon.click(function() {
        $(this).toggleClass("active");
        });


        });

        .container {
        border: 1px solid grey;
        padding: 0.5em;
        text-align: center;
        }

        .icon {
        opacity: 0.5;
        font-size: 48px;
        color: #ddd;
        transition: all 300ms linear;
        cursor: pointer;
        }

        .icon.active {
        opacity: 1;
        color: #bada55;
        }

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <link href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" rel="stylesheet"/>

        <section class="container">

        <span class="icon active">
        <i class="fas fa-stroopwafel"></i>
        </span>

        <span class="icon">
        <i class="fas fa-balance-scale"></i>
        </span>

        </section>








        share|improve this answer















        If it is just about switching classes on click you can use the .toggleClass()-method:
        Link to toggleClass() on http://api.jquery.com.
        Just use your CSS-Class to manipulate the state.






        $(document).ready(function(){

        const icon = $('.icon');

        icon.click(function() {
        $(this).toggleClass("active");
        });


        });

        .container {
        border: 1px solid grey;
        padding: 0.5em;
        text-align: center;
        }

        .icon {
        opacity: 0.5;
        font-size: 48px;
        color: #ddd;
        transition: all 300ms linear;
        cursor: pointer;
        }

        .icon.active {
        opacity: 1;
        color: #bada55;
        }

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <link href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" rel="stylesheet"/>

        <section class="container">

        <span class="icon active">
        <i class="fas fa-stroopwafel"></i>
        </span>

        <span class="icon">
        <i class="fas fa-balance-scale"></i>
        </span>

        </section>








        $(document).ready(function(){

        const icon = $('.icon');

        icon.click(function() {
        $(this).toggleClass("active");
        });


        });

        .container {
        border: 1px solid grey;
        padding: 0.5em;
        text-align: center;
        }

        .icon {
        opacity: 0.5;
        font-size: 48px;
        color: #ddd;
        transition: all 300ms linear;
        cursor: pointer;
        }

        .icon.active {
        opacity: 1;
        color: #bada55;
        }

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <link href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" rel="stylesheet"/>

        <section class="container">

        <span class="icon active">
        <i class="fas fa-stroopwafel"></i>
        </span>

        <span class="icon">
        <i class="fas fa-balance-scale"></i>
        </span>

        </section>





        $(document).ready(function(){

        const icon = $('.icon');

        icon.click(function() {
        $(this).toggleClass("active");
        });


        });

        .container {
        border: 1px solid grey;
        padding: 0.5em;
        text-align: center;
        }

        .icon {
        opacity: 0.5;
        font-size: 48px;
        color: #ddd;
        transition: all 300ms linear;
        cursor: pointer;
        }

        .icon.active {
        opacity: 1;
        color: #bada55;
        }

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <link href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" rel="stylesheet"/>

        <section class="container">

        <span class="icon active">
        <i class="fas fa-stroopwafel"></i>
        </span>

        <span class="icon">
        <i class="fas fa-balance-scale"></i>
        </span>

        </section>






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 2 '18 at 9:15

























        answered Nov 24 '18 at 9:03









        Daniel SixlDaniel Sixl

        1,2621617




        1,2621617






























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456514%2fjquery-what-have-i-done-wrong%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

            Wiesbaden

            Marschland

            Dieringhausen