Using domready for AJAX calls

Is there a way to find out that the elements are in the document before I try to access them using jQuery?

Code snippet:

var s = new AjaxCall(someurl);

s.oncomplete = function(response) {
    var container = $('container_id');
    container.innerHTML = response;
    var ul = $('some_id'); }

The answer is some HTML returned by an Ajax call.

This answer updates the content div, and then I refer to the element that was created innerHTML( ulin code).

If the answer is large, I believe that at times some elements will not be displayed when I try to access them. Does domreadyAJAX support for calls and can this solve my problem?

+3
source share
2 answers

, #, $('#some_id');, $('some_id');. document.getElmenetById. , .

var some_id = document.getElmenetById("some_id");

, " ", . innerHTML . , innerHTML.

+2

jQuery, success :

$.ajax({
  url: "test.html",
  cache: false,
  success: function(resp){
    var ul = $("#containerID").html(resp).find("#ElementInRespID");
    //do something with ul
  }
});

, ul.

0

Source: https://habr.com/ru/post/1732754/


All Articles