How to check if DOM Parser was successful

1.3k views Asked by At
function $(selector) {

    var resultObject = {
        append: function (element) {

          var parser = new DOMParser();
           var dos = parser.parseFromString(element, "text/html");

          if (dos.getElementsByTagName("parsererror ").length == 0)
            {
                alert("SUCESS");
            }
            else
                alert("Error occured while parsing!")

        }
    }
    return resultObject;
}

Call:

    <input type="button" value="append tag/text " onclick="$('.testing').append('<ul><li>yeah</li></ul>');" />

How can I check if my input was valid, because in my function I only check If the tag parseerror exists. Is it possible to check if the parsing was successful without checking after the tag, because if I check the tag it always return that it was successfull...?

0

There are 0 answers