load() is unnesting nested UL / LI elements

load() is unnesting nested UL / LI elements

Hi,

Version: jquery-2.1.4.min.js
Browser: Chrome  46.0.2490.86 (64-bit), Firefox 38.4.0

I could not demonstrate this with jsfiddle as you need more than one HTML file to demonstrate the issue. Furthermore, I could not report this in  http://bugs.jqueryui.com/newticket as the drop down does not show version 2.1.4. Only shows up to version 1.11.4.


Name this as loadTest.html:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.         <meta charset="UTF-8">
  5.         <title>jquery load test</title>
  6. <script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
  7. </head>
  8. <body>
  9. <a href="#loadListOne" onclick="loadListOne();">Load List One<a>
  10. <a href="#loadListOne" onclick="loadListTwo();">Load List Two<a>
  11. <a href="#loadListOne" onclick="loadListThree();">Load List Three<a>
  12.         <ul>
  13.           <li>One
  14.                 <ul id="listOne">
  15.                 </ul>
  16.           </li>
  17.           <li>Two
  18.                 <ul id="listTwo">
  19.                 </ul>
  20.           </li>
  21.           <li>Three
  22.                 <ul id="listThree">
  23.                 </ul>
  24.           </li>
  25.         </ul>
  26.         <script>
  27.         function loadListOne() {
  28.                 $( "#listOne" ).load( "oneList.html #theListForOne li");
  29.         }

  30.         function loadListTwo() {
  31.                 $( "#listTwo" ).load( "twoList.html #theListForTwo li");
  32.         }

  33.         function loadListThree() {
  34.                 $( "#listThree" ).load( "threeList.html #theListForThree li");
  35.         }
  36.         </script>
  37. </body>
  38. </html>

Name this as oneList.html:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.         <meta charset="UTF-8">
  5.         <title>jquery load test</title>
  6. </head>
  7. <body>
  8.         <ul id="theListForOne">
  9.           <li>1.A</li>
  10.           <li>1.B</li>
  11.           <li>1.C</li>
  12.         </ul>
  13. </body>
  14. </html>

Name this as twoList.html:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.         <meta charset="UTF-8">
  5.         <title>jquery load test</title>
  6. </head>
  7. <body>
  8.         <ul id="theListForTwo">
  9.           <li>2.A</li>
  10.           <li>2.B
  11. <ul>
  12. <li>2.B.x</li>
  13. <li>2.B.y</li>
  14. </ul>
  15.           </li>
  16.           <li>2.C</li>
  17.         </ul>
  18. </body>
  19. </html>

Name this as threeList.html:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.         <meta charset="UTF-8">
  5.         <title>jquery load test</title>
  6. </head>
  7. <body>
  8.         <ul id="theListForThree">
  9.           <li>3.A</li>
  10.           <li>3.B
  11. <ul>
  12. <li>3.B.x</li>
  13. <li>3.B.y
  14. <ul>
  15. <li>3.B.y.i</li>
  16. <li>3.B.y.ii</li>
  17. <li>3.B.y.iii</li>
  18. </ul>
  19. </li>
  20. </ul>
  21.           </li>
  22.           <li>3.C</li>
  23.         </ul>
  24. </body>
  25. </html>

Now put them on httpd, etc

Check that the nesting of ULs inside of LIs are displayed by the browser correctly ( specifically for twoList.html and threeList.html ):


Then load the main page:


... then click on "Load List One", "Load List Two", and "Load List Three" ... in any order.

You will notice that the nesting of the ULs inside of LIs is now un-nested by jquery.load().