Sometimes I write a function that I only want to apply to certain pages. Say, a form. I may need some javascript to apply to the form when I’m inserting and different javascript to apply when I’m editing. Since I’m reusing the form, I just change the id
of the form and use this check:
if ($('#insert-form').length > 0) { // do stuff that only applies to the insert form }