Reputation: 81
I have:
<button class="contactButton">XYZ</button>
And when user will press this button I want my page to scroll down to specific div.
I tried this:
$(".contactButton").click(function () {
$("html,body").animate({
scrollTop: $(".specificDivClass").offset().top
}, 1100);
});
Upvotes: 1
Views: 97
Reputation: 973
The problem most likely is misspelling the class name and/or not including the JavaScript to the HTML. You can try using ID instead of class to select the element you want to scroll to.
Upvotes: 1
Reputation: 12181
Here you go with a solution https://jsfiddle.net/psfLbo1n/
$(".contactButton").click(function () {
$("html,body").animate({
scrollTop: $(".specificDivClass").offset().top
}, 1100);
});
.div1{
height: 700px;
width: 100%;
background: red;
}
.specificDivClass{
height: 1000px;
width: 100%;
background: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="contactButton">XYZ</button>
<div class="div1">
</div>
<div class="specificDivClass">
</div>
Upvotes: 3