Connecting emotionally with your reader

If you're anything like me, you like books that engage you emotionally. You get fully invested in characters' lives and suffer through their troubles as if it were you. You feel elation when your hero or heroine achieves their goals. You cheer alongside them as they finally pluck up the courage to talk to their secret crush. You cry when they cry, and even if they don't, you still (possibly) cry. How do we get pulled into these stories so much that we feel the character's pain and joy as if it were our own? Writers use all sorts of tricks to lure you in. One minute you're blissfully enjoying an escape from your own reality, and the next you notice tears falling onto your jeans or your pillow getting soaked. Or you find yourself so irritated with a fictional person that you can't stop reading until the tension eases. How do they do it? How do they do it? How does Jojo Moyes do it? And what can I do to make my readers root for my characters?