Skip to content

Instantly share code, notes, and snippets.

@ambar
Created January 18, 2012 04:33
Show Gist options
  • Save ambar/1630989 to your computer and use it in GitHub Desktop.
Save ambar/1630989 to your computer and use it in GitHub Desktop.
unclosed tag and selectors
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>unclosed tag and selectors</title>
<style type="text/css">
body>div{margin:2em;border:3px dashed gray;height:3em;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script>
$(function() {
console.log([
$.fn.jquery,
$('body>div').length,
$('body').children('div').length
].join('\n'))
})
/*
console
ie7,ie8
1,2
ie9
1,1
cr16,ff9
2,2
*/
</script>
</head>
<body>
<div>
<label>
</div>
<div>check console</div>
</body>
</html>

construction

ie7,ie8

<DIV><LABEL></DIV>
<DIV>check console</DIV></LABEL>

ie9

<div>
  <label></label>
</div>
<label>
  <div>check console</div>
</label>

cr,ff

<div>
  <label></label>
</div>

<div>check console</div>

$.fn.children

// https://github.com/jquery/jquery/blob/2982abbb13454bd4bdf0299f1183fb0d8c02f02d/src/traversing.js#L209
children: function( elem ) {
  return jQuery.sibling( elem.firstChild );
},
// ie9
$.sibling(document.body.firstChild) 
[object HTMLDivElement],[object HTMLLabelElement]
@ambar
Copy link
Author

ambar commented Jan 18, 2012

关闭行为

  • ie7,ie8 是惰性关闭标签;
  • cr,ff 是贪婪关闭标签;
  • ie9 HTML 构造是最奇怪的,label 包含两次,不可理解;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment