After the Civil War, the two parties were united more by ethnocultural factors than by ideology. The Republican Party consisted primarily of Protestant, Northern whites, while the Democratic Party was a coalition of white Southerners and Northern, urban "ethnic whites" (i.e. Irish, Italians, Jews...essentially white non-WASPs). In the 1930s, Jewish voters became a key part of the New Deal coalition, which to some degree was an enhanced version of the already-existing Democratic coalition (though it also incorporated other groups, e.g. unions and African Americans).
In the 1970s, Democrats began losing ground with other ethnic whites for various reasons (suburbanization, racial turmoil, etc.). During this period, some Jewish voters also moved towards the Republican Party, though not to the same degree as other white ethnic groups. As the Republican Party increasingly became the party of evangelical Protestantism in the 1980s and 1990s, Jewish voters moved back into the Democratic Party.
If you look at
political affiliation by religion, there's a spectrum with Mormons and evangelical Protestants being strongly Republican, mainline protestants and Catholics split roughly down the middle, Jews, Orthodox Christians, atheists, agnostics, Hindus, and Buddhists leaning towards the Democratic Party, and African-American churches leaning strongly towards the Democratic Party.