Bug Tracker

Ticket #5316: jquery-replaceall-testcase.html

File jquery-replaceall-testcase.html, 1.6 KB (added by Perceptes, 10 years ago)

A test case to show the issue, run it in a browser to see what's happening.

Line 
1<!DOCTYPE html>
2<html>
3<head>
4  <title>jQuery replaceAll multiple elements</title>
5  <meta charset=utf-8 />
6  <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript" charset="utf-8"></script>
7  <script type="text/javascript" charset="utf-8">
8    $(function() {
9      $('#one').click(function() {
10        $('<div><p>1</p><p>2</p></div>').replaceAll('#replaceme');
11        showResults();
12        return false;
13      });
14     
15      $('#two').click(function() {
16        $('<p>1</p><p>2</p>').replaceAll('#replaceme');
17        showResults();
18        return false;
19      });
20     
21    });
22   
23    function showResults() {
24      if ($('#content p').length == 2) {
25        $('#result').text('PASS');
26      } else {
27        $('#result').text('FAIL').css('color', 'red');
28      }     
29    }
30  </script>
31</head>
32<body>
33  <div id="explanation">
34    <p>jQuery's <a href="http://docs.jquery.com/Manipulation/replaceAll">replaceAll</a> does not insert any element after the first if called on a block of HTML that contains multiple sibling elements.</p>
35   
36    <p>This page must be reloaded between tests.</p>
37  </div>
38 
39  <form>
40    <button id="one">Replace element with: &lt;div&gt;&lt;p&gt;1&lt;/p&gt;&lt;p&gt;2&lt;/p&gt;&lt;/div&gt;</button><br />
41    <button id="two">Replace element with: &lt;p&gt;1&lt;/p&gt;&lt;p&gt;2&lt;/p&gt;</button>
42  </form>
43 
44  <div id="content" style="display: none;">
45    <div id="replaceme">
46      This will be replaced.
47    </div>
48  </div>
49 
50  <div id="result" style="margin-top: 12px; font-size: 24px; color: green;"></div>
51</body>
52</html>