I shot an elephant in my pajamas...
This comedic sentence, as delivered by Groucho Marx, capitalizes on one of the most common errors made by English writers and speakers: the misplaced modifier.
A misplaced modifier is a word or phrase that acts on something other than what the writer or speaker intended. The comedy in the sentence above is that Groucho was in his pajamas when he shot the elephant, not that the elephant was physically in his pajamas. See how a misplaced modifier works?
In general, the modifier should be closest to the word on which it is acting. Let’s look at another example.
"After barking in the house, Johnny let his dog outside."
Do you see the misplaced modifier? Of course you do. Johnny wasn’t the one who was barking; his dog was barking. So the sentence could be corrected by changing it to the following:
"After barking in the house, the dog was let outside by Johnny."
As you write, it is imperative to continually review your sentence structure to ensure that your intended sentence meaning is not taken out of context by using misplaced modifiers.
After all, who wants an elephant in his or her pajamas?