Read this passage and open each verse for the full verse feed and commentary tools.
6Judah took a wife for Er, his firstborn, and her name was Tamar. 7Er, Judah`s firstborn, was wicked in the sight of Yahweh. Yahweh killed him. 8Judah said to Onan, "Go in to your brother`s wife, and perform the duty of a husband`s brother to her, and raise up seed to your brother." 9Onan knew that the seed wouldn`t be his; and it happened, when he went in to his brother`s wife, that he spilled it on the ground, lest he should give seed to his brother. 10The thing which he did was evil in the sight of Yahweh, and he killed him also.
Genesis 38:6-10 (WEB)