How to add onload event to div and p? ##PremiseIn fact, there are only , , , , , < ;script>, only these tags have onload events, while div, p and other tags do not. <p></p>But what if we still want to do something when the div is appended to the DOM? Some people will say that it is enough to just add it after the code that appends to the DOM, but this will have to be written after each append place one by one, which is very troublesome. <p></p> <p>For example<strong></strong><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:js;toolbar:false"><div> <p>我有一只小毛驴,我从来也不骑。</p> </div></pre><div class="contentsignin">Copy after login</div></div></p>Suppose I want to pop up the "I am a little donkey" prompt box after the above content is loaded. <p></p><p>Borrowing Flowers to Offer Buddha<strong></strong></p> I still want to use onload event processing. We also know which tags are supported, so we can change the code to: <p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:js;toolbar:false"><div> <p>我有一只小毛驴,我从来也不骑。</p> <style onload="alert('我是小毛驴')"> Copy after login In this way, by borrowing the style tag, as long as the div is appended to the DOM, the onload event can be simulated to be triggered. This article comes from the js tutorial column, welcome to learn!