Where does the phrase to cotton to a thing or person come from?

We are apt to look upon this as recent, forgetting that it was used by Dickens (Old Curiosity Shop) more than a hundred years ago with just the present meaning, to get along with or to like a thing or person.

And it was not original with Dickens, for it was used more than thirty years earlier.

In fact, the usage appears to be little more than an extension of a meaning that was popular back in the middle of the sixteenth century, in a phrase, now obsolete, “This gear cottons,” meaning this matter goes well or prospers.

The origin is lost, but probably referred in some manner to the readiness with which cotton adheres to a napped surface.