Reputation: 69
I had jQuery append html parsed from AJAX into a <table>
.
And I have to get the value fron class='msg'.
But it doesn't show on the source code. So I can't get the value. Can you explain me what my problem is?
function showHtml(data){
var str = "<tr><td class='msg'>" + data.msg + "</td></tr>";
$("tbody").append(str);
}
$.ajax({
url: "----",
type: "POST",
dataType: "html",
data: {
msg : msg
},
success: function(json) {
data = JSON.parse(json);
showHtml(data);
}
});
Upvotes: 1
Views: 152
Reputation: 93
Dynamic created html should not be displayed at "View Source" window.
You can find the real time content at the inspector of each browser.
Example Firefox: Right button page / Inspect -> Inspector Tab
You can also work with the dynamic created content:
function showHtml( data )
{
var str = "<p>" + data + "</p>";
$( "#myDiv" ).append( str );
}
var data = 'DATA TEST';
//Appending data
showHtml( data );
//Logging data
console.log( $( '#myDiv' ).html() );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv"></div>
Upvotes: 1