Home > Article > Backend Development > How to avoid the non-existence of a certain element in html causing js to obtain the attribute information of the element and report an error
The page code is as follows:
<code><empty name="search_data"> <div class="box"> <!-- html代码 --> </div> </empty> <script> var top = $('.box').offset().top; $("html,body").scrollTop(top); </script></code>
As above,