How to add onload event to a div element

前端 未结 24 2255
谎友^
谎友^ 2020-11-22 00:26

How do you add an onload event to an element?

Can I use:

for t

24条回答
  •  名媛妹妹
    2020-11-22 01:02

    You can attach an event listener as below. It will trigger whenever the div having selector #my-id loads completely to DOM.

    $(document).on('EventName', '#my-id', function() {
     // do something
    });
    

    Inthis case EventName may be 'load' or 'click'

    https://api.jquery.com/on/#on-events-selector-data-handler

提交回复
热议问题