I select the option label with scrollbar to view the contents of the dropdown list. I want that when we click to select an item, the scrollbar should be at the bottom.
jquery code $('document').ready(function(){ $('#textin1').click(function() { var pos = $('#textin1').offset(); pos.top += $('#textin1').width(); $('#dropdown').fadeIn(100); $('#dropdown').scrollTop($('#dropdown').find('li:contains("'+$('#textin1').val()+'")').position().top); return false; }); $('#dropdown li').click(function() { $('#textin1').val($(this).text()); $('#dropdown li').removeClass('selected'); $(this).addClass('selected'); $(this).parent().fadeOut(100); }); });
P粉2877263082023-09-16 17:53:15
Try this maybe it will work for you
const scrolling = document.getElementById("scroll"); const config = { childList: true }; const callback = function (mutationsList, observer) { for (let mutation of mutationsList) { if (mutation.type === "childList") { window.scrollTo(0, document.body.scrollHeight); } } }; const observer = new MutationObserver(callback); observer.observe(scrolling, config);