Bug Tracker

Opened 8 years ago

Closed 8 years ago

#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:
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>

Change History (1)

comment:1 Changed 8 years ago by brandon

  • Resolution set to invalid
  • Status changed from new to 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.

Note: See TracTickets for help on using tickets.