Hide / Collapse items that are not present in the database

Do you repeat and copy the same javascript shown in the tutorial each time for every item you want to hide? Or is there more syntactically correct way to do it?