Bug Tracker

Ticket #1626 (closed bug: invalid)

Opened 7 years ago

Last modified 7 years ago

.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

comment:1 Changed 7 years 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.