I have done this functionality in a static way but how can i do this scroll using jquery so that it will smoothly scroll to the particular element which id i have added dynamically.
var data = [{"name": "Aruba", "code": "A"},{"name": "AndorrA", "code": "A"},{"name": "Bhutan", "code": "B"},{"name": "Bolivia", "code": "B"}]
var num=0;
$.each(data, function(key, val) {
if (!$("#aZContent ul." + val.code).is("*")) {
$("<ul />", {"class": val.code,"html": "<li>"+ val.name + "</li>"}).appendTo("#aZContent").before('<b class=' + val.code + ' id="letter_' + num++ + '">' + val.code + '</a></b>');
} else {
$("b." + val.code).each(function() {
if (this.textContent === val.code) {
$(this).next("ul").append("<li>" + val.name + "</li>");
}
});
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="alphabet" id="alphaTab">
<a href="#letter_0">A</a>
<a href="#letter_1">B</a>
</div>
<div id="aZContent">
<ul></ul>
</div>
<div style="height:500px"></div>
On Click of link 'A' it should scroll to the "A" and likewise