Fix "normalized" (broken) lists in IE (think innerHTML)


/ Published in: JavaScript
Save to your folder(s)

Developed as part of my DCODR experiments...


Copy this code and paste it in your HTML
  1. // Is explorer "normalisating" my closing </li> tags?
  2. fixLists = function (html) {
  3. if (navigator.userAgent.indexOf ("MSIE") != -1) {
  4. // Convert <li> to </li><li>
  5. html = html.replace (/<li(\s+[^>]*)?>/gi, "</li><li$1>");
  6. // Then remove any that double up with the opening tag
  7. html = html.replace (/(<(ul|ol)(\s+[^>]*)?>)\s*<\/li>/gi, "$1");
  8. }
  9. // And relax
  10. return html;
  11. };

URL: http://oopstudios.com/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.