Is there a way to change the text color in
$('td:contains("text")').css('color','red')
after an Ajax load script?
Here is the main code snippet
<div id="datatable"></div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script id="body">$(document).ready(function(){$.ajax({url:"script.js",type:"POST",cache:!1,success:function(c){c&&$("#body").append(c)}})});$('td:contains("text")').css('color','red');alert("script")</script>
Code for script.js
var datatable = document.getElementById("datatable");
var table = "<table><tr><td id='tdone'>Text</td></tr>" +
"<tr><td id='tdtwo'>Two</td></tr></table>";
datatable.appendChild(table);
alert("code");
I'm facing an issue with the order of alerts, where the Script
alert pops up before the code
alert.
Are there any methods or techniques to wait until the Ajax call finishes and the table is appended to the document before firing the script?
I have tried using Success, Complete, Find, and AjaxStop methods but none of them seem to work.