Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript .addClass()/.removeClass() not working as expected.

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #158777
    Dami
    Participant

    From what I can tell, these methods are exactly what I’m looking for.

    What I’m trying to do is have a set of buttons change based on the value selected in a radio group. I’ve tried .hide() and .show(), but they’re not working either. (By “not working” I mean nothing happens. The coded changes aren’t applied.)

    http://codepen.io/anon/pen/zvscr Here is my current code. What am I doing wrong? This probably doesn’t need to be said, but jquery/javascript are not my strong suits. :(

    Any insights are appreciated. TIA

    #158778
    __
    Participant

    couple things:

    in a Codepen, you don’t use <script> tags inside the js box. If you look at your console, you’ll see a syntax error:

    Syntax Error: Unexpected token <

    After you fix that, you’ll see this error:

    Reference error: $ is not defined

    You don’t have jQuery on your page. Remember, it’s a library, not part of the javascript core.

    corrected codepen

    #158783
    Dami
    Participant

    Thank you for the tips on using Codepen, I appreciate that. :)

    I see it’s working with your changes, but it sure as heck isn’t working on my page. :( At least your changes shows me it’s probably not the code, but something else that’s interfering (though the codepen code was cut and pasted from the page’s view source).

    Many thanks!! :)

    #158785
    __
    Participant

    You’re welcome.

    I see it’s working with your changes, but it sure as heck isn’t working on my page.

    Could you share a link to your page?

    Did you make sure to add the jQuery script?

    #158786
    Dami
    Participant

    I would love to, but it’s under password protection. :( Thanks.

    Yes, the link to jquery is included on the page.

    #158788
    __
    Participant

    Yes, the link to jquery is included on the page.

    before you try to use $? Do you have some other var or library that tries to use $ on the same page? Try (if you’re in chrome, for example) console.log($).

    #158883
    Dami
    Participant

    Thanks, traq, I got it working. There was another error on the page that was interfering with the jquery script.

    Appreciate the help.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.