Genesis 38:9

9 However, Onan knew that the child would not count as his; so whenever he had intercourse with his brother's wife, he spilled the semen on the ground, so as not to give his brother offspring.

Genesis 38:9 Meaning and Commentary

Genesis 38:9

And Onan knew that the seed should not be his
Should not be called a son of his, but a son of his brother Er; this is to be understood only of the firstborn; all the rest of the children born afterwards were reckoned the children of the real parent of them; this shows this was a custom in use in those times, and well known, and was not a peculiar case: and it came to pass, when he went in unto his brother's wife;
to cohabit with her, as man and wife, he having married her according to his father's direction: that he spilled [it] on the ground, lest he should give his seed to
his brother:
lest his brother's wife he had married should conceive by him, and bear a son that should be called his brother's, and inherit his estate; and this is the sin, which from him is called Onania, a sin condemned by the light of nature, as well as by the word of God, and very prejudicial to mankind, as well as displeasing to God, as follows:

Genesis 38:9 In-Context

7 But 'Er, Y'hudah's firstborn, was evil from ADONAI's perspective, so ADONAI killed him.
8 Y'hudah said to Onan, "Go and sleep with your brother's wife - perform the duty of a husband's brother to her, and preserve your brother's line of descent."
9 However, Onan knew that the child would not count as his; so whenever he had intercourse with his brother's wife, he spilled the semen on the ground, so as not to give his brother offspring.
10 What he did was evil from ADONAI's perspective, so he killed him too.
11 Then Y'hudah said to Tamar his daughter-in-law, "Stay a widow in your father's house until my son Shelah grows up"; for he thought, "I don't want him to die too, like his brothers." So Tamar went and lived at home with her father.
Complete Jewish Bible Copyright 1998 by David H. Stern. Published by Jewish New Testament Publications, Inc. All rights reserved. Used by permission.