I don't want to drag the OP's thread off course with a minor dispute, but please note the word highlighted in bold above. The OP's clear intention was to refer to the specific problem which was actually attached in his second post!
You correctly pointed out that textbooks often gloss over the fact that we can only write tan x = sin x / cos x when tan x is defined, but you weren't correcting any of the previous posters because they explained that we needed cos x not equal to zero for the division to be valid, and this condition is precisely the same as saying 'tan x is defined'
Hopefully the OP has enough from all of us to have a better understanding of why the process was correct for the specific problem he attached. It's better to see students asking about this than blindly assuming we can divide by things all the time, which is the more common error!
EDIT: beaten by Zacken while I was composing my essay