The asteroid belt is affected by Jupiter's gravity.
There are stable orbits inside of Jupiter's orbit. Jupiter's Hill Sphere has a radius of 53 million km. If you are more than 53 million km from Jupiter, then the Sun's gravity dominates and you can orbit the sun. But Jupiter orbits 780 million km from the Sun, so there is plenty of space between Mars and Jupiter for asteroids to have stable orbits.
As they pass Jupiter on their orbit they will get first a pull forward, and then a pull back but as these pulls happen at different locations on each orbit they tend to cancel out and result in effects like precession of the asteroid's perehelion or periodic variations in eccentricity. These effect act on the Earth and other planets too.
However if the time the asteroid takes to orbit the sun happens to be an exact fraction of the time that Jupiter takes, then it might receive the same pull at the same location. Resonant orbits like this tend to be unstable. The asteroid will be nudged out of the resonant orbit and into one that doesn't match up with Jupiter. This creates the Kirkwood Gaps in the asteroid belt.

Source