How to access dynamically created page elements using jQuery (not events, ELEMENTS!)

I have several dynamically created elements on a page that I would like to POST content using jQuery to another page. The problem is that the created elements cannot be accessed through jQuery (access to the elements that existed on the page can be obtained using $ (# myElementID). I have seen hundreds of messages using the live () and on () functions to access EVENTS, but not having access to any properties, values, innerHTML, etc. Dynamically created ELEMENTS. Is it just impossible to do with jQuery?

    $('#btnParseTable').click(function () {
        var tblCustomPattern = $("#tblCustomPattern").innerHTML; 


   //This test alert yields "" because tblCustomPattern is undefined - yet FireBug clearly shows the table exists!
        alert(tblCustomPattern); 


 var postData = { "method": "ParseTable", "tbl": tblCustomPattern };
        $.post("tiler.aspx", postData, function (data) {
            $("#test").html(data); //for testing
        });

});

If this is not supported by jQuery, can this be done in JavaScript or is it impossible to send information that is NOT an INPUT element?

+4
2

:

$("#tblCustomPattern").innerHTML;

, $("#tblCustomPattern") jQuery. DOM. jQuery .innerHTML.

, , :

  • DOM jQuery, .innerHTML DOM.
  • jQuery , jQuery .html().
  • jQuery , JS.

, :

// get the first DOM object from the jQuery object
//    two different methods for doing that
var tblCustomPattern = $("#tblCustomPattern")[0].innerHTML; 
var tblCustomPattern = $("#tblCustomPattern").get(0).innerHTML; 

// use the jQuery method to get the HTML
var tblCustomPattern = $("#tblCustomPattern").html();

// use plain JS - fastest option
var tblCustomPattern = document.getElementById("tblCustomPattern").innerHTML;
+1

"", tblCustomPattern undefined - FireBug , !

DOM. tblCustomPattern - undefined, jQuery innerHTML DOM innerHTML, jQuery. indexer [] [get()][1], html jQuery. zero-based, index.

var tblCustomPattern = $("#tblCustomPattern")[0].innerHTML; 

, . get()

var tblCustomPattern = $("#tblCustomPattern").get(0).innerHTML; 

html()

var tblCustomPattern = $("#tblCustomPattern").html(); 
+2

All Articles