Forums

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

Home Forums JavaScript Help with jQuery if/else

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #34881
    Arvid
    Member

    I’m having a javascript file in which I checked whether or not an element had a certain classname using an if/else statement. However, if/else only seems to execute once and I was wondering how (if) it would be possible to have it loop, perhaps using the while loop? If it’s possible, how would I do it? I apreciate any help, thanks!

    Current code:

    if($('element').hasClass("className")) {

    }
    else {

    }
    #89485
    jamygolden
    Member

    You would have to bind the if/else to an event.
    Once something is clicked, the if/else runs, or once something is hovered, or once the page has loaded. When do you want your if/else to be executed?

    #89490
    Arvid
    Member

    Thanks!

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