Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have HTML page that has Ajax call to load table content

<html>
....

<script sec:haspermission="VIEW_NOTE" th:inline='javascript'>
        require(['app/agent/viewGlobalAgent'], function (){
            var individualId= [[${model.agent.individual.id}]];
            var agentId= [[${model.agent.id}]];
            $.get("/notes/referenceTable.html?individualId="+individualId+"&agentId="+agentId, function(data){
                console.log("theData " , data);

                var noteList = $("#note-list-container2").value;
                var fileList = $("#file-list-container2").value;
                // document.getElementById("note-list-container").innerHTML = noteList;
                // document.getElementById("note-file-form").innerHTML = fileList;
                $("#note-list-container").html(noteList);
                $("#note-file-form").html(fileList);

        
        });
    </script>

....
</html>

the html that Ajax call load

<div>
<div id="note-list-container2">
    ....
</div>
<div id="file-list-container2">
....
</div>
</div>

I need to access these two div on callback of Ajax call

$.get("/notes/referenceTable.html?individualId="+individualId+"&agentId="+agentId, function(data){

I tried to access them but its not working

$("#note-list-container2").value

is any way to access div in loaded html

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
617 views
Welcome To Ask or Share your Answers For Others

1 Answer

Since you want content from within the new html returned as data you want to wrap that data in $() and query within that object

Then use text() or html() since value is only for form controls, not content elements

$.get(url, function(data) {

  var $data = $(data);

  var noteList = $data.find("#note-list-container2").text();// or html()
  var fileList = $data.find("#file-list-container2").text();

  $("#note-list-container").html(noteList);
  $("#note-file-form").html(fileList);

});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

Just Browsing Browsing

[3] html - How to create even cell spacing within a

548k questions

547k answers

4 comments

86.3k users

...