简体   繁体   中英

jQuery trigger on event when other script is loaded / element from other script is created

I need to change the text inside a dynamically generated p element after this element is from another script.

The adobe edge script creates two p elements inside #Stage. I need to change the text inside these p elements after they are created.

I actually can change the text with the on.("click") event but i need to fire this event as soon as the p elements are genereated.

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>

    <script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
    <script type="text/javascript" charset="utf-8" src="edge_includes/edge.6.0.0.min.js"></script>

</head>
    <body>
        <div id="Stage">

        </div>

        <script type="text/javascript">
            $( "#Stage" ).on( "click", "p", function() {
                $("#Stage p").text("New Content");
            });
        </script>


    </body>


</html>

Hope this helps:

  $(function(){ $("<p></p>").appendTo($("#Stage")); $("<p></p>").appendTo($("#Stage")); $("<p></p>").appendTo($("#Stage")); }); $("#Stage p").livequery(function () { $("#Stage p").text("New Content"); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/livequery/1.1.1/jquery.livequery.min.js"></script> <div id="Stage"></div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM