People at a crosswalk

Did Jesus teach that only those who believe in him go to heaven?

Short answer: Jesus taught that the Father in heaven loves all men and women with equal affection. He taught that God is a loving creator parent who is no respecter of persons. He loves everyone no matter your race, religion, social status, or intellectual capability. To qualify for "heaven" after you leave this world you must have faith. The Father of all responds to even the faintest flicker of faith in God. He wants none of his children to perish.

To gain a much better understanding of this answer, read the following:

"The kingdom of heaven is open to all men and women. No man may close the door of mercy in the face of any hungry soul who may seek to gain an entrance thereto...As our Father in heaven looks down upon men, they are all alike. Refuse not therefore to break bread with Pharisee or sinner, Sadducee or publican, Roman or Jew, rich or poor, free or bond. The door of the kingdom is wide open for all who desire to know the truth and to find God." (138:4.2)

"...you cannot thus shut up the doors of the kingdom of heaven; these we have opened to all who have the faith to enter, and these portals of mercy shall not be closed by the prejudice and arrogance of false teachers and untrue shepherds who are like whited sepulchres which, while outwardly they appear beautiful, are inwardly full of dead men's bones and all manner of spiritual uncleanness." (166:1.5)

Though Jesus taught that faith, simple childlike belief, is the key to the door of the kingdom, he also taught that, having entered the door, there are the progressive steps of righteousness which every believing child must ascend in order to grow up to the full stature of the robust sons of God. (170:3.2)

God is spirit, and God gives a fragment of his spirit self to dwell in the heart of man. Spiritually, all men are equal. The kingdom of heaven is free from castes, classes, social levels, and economic groups. You are all brethren. (134:4.7)

Facing Eternity (detail) by Del Parson"This kingdom is an everlasting dominion. Those who enter the kingdom shall ascend to my Father; they will certainly attain the right hand of his glory in Paradise. And all who enter the kingdom of heaven shall become the sons of God, and in the age to come so shall they ascend to the Father. And I have not come to call the would-be righteous but sinners and all who hunger and thirst for the righteousness of divine perfection." (137:8.16)

"John came preaching repentance to prepare you for the kingdom; now have I come proclaiming faith, the gift of God, as the price of entrance into the kingdom of heaven. If you would but believe that my Father loves you with an infinite love, then you are in the kingdom of God." (137:8.17)

"Happy are the poor in spirit, the humble, for theirs are the treasures of the kingdom of heaven." (140:3.3)

"Happy are they who are persecuted for righteousness' sake, for theirs is the kingdom of heaven. Happy are you when men shall revile you and persecute you and shall say all manner of evil against you falsely. Rejoice and be exceedingly glad, for great is your reward in heaven." (140:3.11)

John asked Jesus, "Master, what is the kingdom of heaven?" And Jesus answered: "The kingdom of heaven consists in these three essentials: first, recognition of the fact of the sovereignty of God; second, belief in the truth of sonship with God; and third, faith in the effectiveness of the supreme human desire to do the will of God—to be like God. And this is the good news of the gospel: that by faith every mortal may have all these essentials of salvation." (140:10.9)