Side navigation
#1626 closed bug (invalid)
Opened September 16, 2007 06:55AM UTC
Closed September 18, 2007 01:57PM UTC
.before() behaves inconsistently when prepending objects
| Reported by: | wet | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | core | Version: | 1.2 |
| Keywords: | Cc: | ||
| Blocked by: | Blocking: |
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>
Attachments (0)
Change History (1)
Changed September 18, 2007 01:57PM UTC by comment:1
| resolution: | → invalid |
|---|---|
| status: | new → closed |
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.