Does the ".load()" at least work?

-  Your first method ---------------------------------
$("#thisDiv").text("<").replaceWith("&lt");

that's going to fill "#thisDiv" with "<"


-  Your second method -------------------------------
$("#thisDiv").text().html();

is going to be a string value after ".text()" and would throw an error
because there is no ".html()" method on a string object


- Your third attempt -----------------------------------
Would have worked, except you are missing the fact that the ".load"
call is an asynchronous call, meaning you have no control over the
object so soon to use the ".html()" method

So with all that said (with help of some "Html Encode" code that i
found by Google-ing):

$("#thisDiv").load("../sample.html", { }, function() {
    var div = document.createElement("div");
    var text = document.createTextNode($("#thisDiv").html());
    div.appendChild(text);
    var EscapedHTML = div.innerHTML;
});



On Apr 3, 5:05 pm, Nikola <nik.cod...@gmail.com> wrote:
> Hello,
>
> I'm trying to load an external HTML file and encode the < with &lt.
>
> I've tried a number of different approaches but I haven't found the
> proper method yet. Here are a few examples of how I've approached
> this..
>
> $("#thisDiv").load("../sample.html");
> $("#thisDiv").text("<").replaceWith("&lt");
> __
>
> $("#thisDiv").load("../sample.html").text();
> $("#thisDiv").text().html();
> __
>
> $("#thisDiv").load("../sample.html").text();
> $("#thisDiv").text().replace(/</g,'&lt;');
>
> Any suggestions or ideas?

Reply via email to