- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Can this be done neater?
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′);
});
Without the HTML it’s hard to comment
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?
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…
Thank you Shikkediel, That was what i was looking for, I was worried i was calling jQuery too may times.
GP