Here is my code, which does not show any error, but don't go to href
location either.
Code works when I change href
to "www.google.com". Why it does not work for same page link?
<form>
<a href="#DivIdToScroll">
<div id="btnLink" onClick="generateReport();"> Generate </div>
</a>
</form>
<script>
function generateReport()
{
window.location.href = '#DivIdToScroll';
}
</script>
I prepared a code snippet from the code you provided. I just made a long container, and inserted a div with the Id "DivIdToScroll" in the lower part. It seems to be working alright. You may have used a class instead of Id. Hope it helps.
function generateReport() {
window.location.href = '#DivIdToScroll';
}
.longContainer {
height: 1000px;
background: #eee;
}
.justTakingSpace {
height: 600px;
margin: 2px;
background: #ddd;
}
<div class="longContainer">
<form>
<a href="#DivIdToScroll">
<div id="btnLink" onClick="generateReport();">Generate</div>
</a>
</form>
<div class="justTakingSpace"></div>
<div id="DivIdToScroll">Oh you're here at "#DivIdToScroll". hello hello.</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With