With jQuery 1.11.3, I found elements are disordered in IE<9, when I append() a bundle of elements including text node. Is this jQuery bug, or mine?
Test Code:
<!DOCTYPE html>
<html>
<head>
<title>jQuery test</title>
<script src="http://code.jquery.com/jquery-1.11.3.js" charset="utf-8"></script>
</head>
<body>
<div id="div"></div>
<script>
$('#div').append(
$('<span/>', {
css: {
color: 'red'
},
text: 'Some'
}).add(
$(document.createTextNode(' Texts '))
).add(
$('<span/>', {
css: {
fontSize: 'x-large'
},
text: 'are'
})
).add(
$(document.createTextNode(' appended.'))
)
);
</script>
</body>
</html>
In IE 11 (and all other modern browsers):
In IE 8 emulation mode:
$(..).append($(..).add(..).add(..).add(...))
, control the insertion order more directly with this;$(...).append(...).append(...).append(...)
. The first one relies on the DOM order inside the jQuery object after.add()
. It would be better to directly control the.append()
order yourself.add
, like this -> jsfiddle.net/adeneo/yryr026w