Forums

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

Home Forums JavaScript Can this be done neater?

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #245403
    Gary Pickles
    Participant

    I have a function written using jQuery, it works fine, does everything i need it to do, My question is can this be written neater or better?

    “`
    $(document).on(‘click’, ‘#submit’, function(){
    event.preventDefault();
    $( ‘#submit-wrapper’ ).hide();
    $( ‘#submit-message’ ).hide();
    $( ‘#start-wrapper’ ).show();
    $(‘#divId’).timer(‘remove’);
    $(‘#divId’).html(’00:00′);
    });

    #245411
    Paulie_D
    Member

    Without the HTML it’s hard to comment

    #245429
    I.m.learning
    Participant

    The only thing I can think of (without better understanding–see Paulie’s post) is by usingvan external file to hold the codes.

    JSON and PHP could be used. Now, sometimes making code neater means adding more lines of code.

    Do you want neater code, or simpler code?

    #245434
    Shikkediel
    Participant

    You could combine a few things in any case. Preventing the default action won’t work if the event itself isn’t defined by the way.

    $(document).on(‘click’, ‘#submit’, function(event) {
    event.preventDefault();
    $(‘#submit-wrapper, #submit-message’).hide();
    $(‘#start-wrapper’).show();
    $(‘#divId’).timer(‘remove’).html(’00:00′);
    });
    

    I’m assuming .timer is a method that belongs to some plugin…

    #245532
    Gary Pickles
    Participant

    Thank you Shikkediel, That was what i was looking for, I was worried i was calling jQuery too may times.

    GP

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