Bug Tracker

Ticket #1626 (closed bug: invalid)

Opened 1 year ago

Last modified 1 year ago

.before() behaves inconsistently when prepending objects

Reported by: wet Assigned to: anonymous
Type: bug Priority: major
Milestone: Component: core
Version: 1.2 Keywords:
Cc: Needs: Review

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

Change History

Changed 1 year ago by brandon

  • status changed from new to closed
  • resolution set to invalid

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.

Note: See TracTickets for help on using tickets.