Check if HTML snippet is valid with Javascript

前端 未结 7 1959
忘了有多久
忘了有多久 2020-11-29 05:03

I need a reliable Javascript library / function to check if a HTML snippet is valid that I can call from my code. For example, it should check that opened tags and quotation

相关标签:
7条回答
  • 2020-11-29 05:56

    It depends on js-library which you use.

    Html validatod for node.js https://www.npmjs.com/package/html-validator

    Html validator for jQuery https://api.jquery.com/jquery.parsehtml/

    But, as mentioned before, using the browser to validate broken HTML is a great idea:

    function tidy(html) {
        var d = document.createElement('div');
        d.innerHTML = html;
        return d.innerHTML;
    }
    
    0 讨论(0)
提交回复
热议问题