Modify ↓
Ticket #1626 (closed bug: invalid)
.before() behaves inconsistently when prepending objects
| Reported by: | wet | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | core | Version: | 1.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
This snippet is producing unexpected results, as the first invokation of .before() apparently results in no output changes
<html>
<head>
<script src="jquery-1.2.js" type="text/javascript"></script>
<script>
$(document).ready(
function(){
var baz = $("<p>").text("baz");
$("a[href*='#test1']").before(baz);
$("a[href*='#test1']").before("foo");
$("a[href*='#test2']").before(baz);
$("a[href*='#test2']").before("bar");
}
);
</script>
</head>
<body>
<a href="#test1" id="test1">test1</a>
<a href="#test2" id="test1">test2</a>
</body>
</html>
Expected HTML:
<p>baz</p>foo<a href="#test1" id="test1">test1</a> <p>baz</p>bar<a href="#test2" id="test1">test2</a>
Rendered HTML in IE7 and FF2 misses the first instance of 'baz':
foo<a href="#test1" id="test1">test1</a> <p>baz</p>bar<a href="#test2" id="test1">test2</a>
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

baz is a single element and can only be inserted into the DOM in one place. You could clone the baz element to get the desired result.