...

JQuery find id after loading

Here is my structure:

Person.html

...
<script src="../../js/site.js"></script>
...
<a id="findPersonById" href="javascript:void(0);" class="btn btn-primary">
Find person by id</a>
...
<div id="person-result">results div</div>

      

Site.js

$(document).ready(function () {
  privateFunction();
});
...
$('#findPersonById').click(function () {
  $("#person-result").load('/person/find #inside-container');
});
...

      

/ person / find

<script src="../../js/site.js"></script>
...
<div class="container">
<div id="inside-container">
    <br/>
    <form id="personFindByIdForm">
        <div class="form-group">
            <div class="input-group">
                <span class="input-group-addon">PERSON ID</span>
                <input type="text" class="form-control" name="id"/>
                <span class="input-group-btn">
                    <button class="btn btn-default" type="submit">Find</button>
                </span>
            </div>
        </div>
    </form>
    <div id="find-result">res-div</div>
</div>

      

So, first of all I find #findPersonById

and upload /person/find #inside-container

to #person-result

. It works. My next step was to find two IDs #personFindByIdForm

and #find-result

. I cannot do this as the document is already loaded, if I am correct. How can i do this? And the second question is, if I add some js code to a div that gets loaded into another div, will this js code run (why doesn't it work)? For example:

$("#div-2").load('/any-url #div-1');
<div id='div-1'>
  <script>console.log('Any JS')</script>
</div>

      

Thank.

+3


source to share


1 answer


You can make sure the items are loaded like this:



$("#div-2").load('/any-url #div-1', function(){
     //here all the items loaded will be accessible

});

      

+5


source







All Articles