I have a responsive panel that changes based on the width of the web browser. Based on the number of list items I want a block to be displayed. For instance, if there are two list items I want the block to be displayed at window width of 500px.
My question is: What would be the best and most optimized method for doing this?
Current code to get number of list items in ul:
document.querySelectorAll("#ulClass li").length
My current thought is to use a switch on a window resize event:
window.addEventListener('resize', function(event){
// do stuff here
});
Note:
- I need to use plain JavaScript, no plug-ins, etc.
- I can't use Resize Observer.