Adding the input element inside the div makes the code execute faster since it just has to search only under the div element and not the entire DOM. If you want to place the input element outside, then too you could make your code optimized by using