Teaching children to be respectful of pets doesn't mean they can't stroke the family dog or cat: It's about doing it safely. Dogs and cats both use body language to say when they don't want to be petted.
If dogs are crouching with their ears flat, have their hackles raised, or have their tail between their legs, it can mean they're nervous and may bite. There are also more subtle signs of stress, such as lip licking and a tucked tail.
Cats have similar "tells". For example, if they are crouched and stiff with open and unblinking eyes or have bristling whiskers or a fluffed out tail, don't try to play! Flat ears and lifting a paw are a less obvious sign of your cat being anxious.