Skip to main content

Bug Tracker

Side navigation

#10406 closed bug (fixed)

Opened October 02, 2011 11:26PM UTC

Closed July 18, 2014 12:32AM UTC

:hidden selector finds <br /> elements in chrome and safari (but not FF or IE)

Reported by: jen@littlegreenpixel.com Owned by: timmywil
Priority: high Milestone: 1.12/2.2
Component: css Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:
Description

When using .find(':hidden') , Chrome and Safari return <br /> elements in addition to elements that you would expect. Firefox and IE (9) do not find <br /> elements.

Test case:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal">
<head>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
  <script type="text/javascript">
	$(document).ready(function() {
		var hidden_elements = $('#test').find(':hidden');
		console.log(hidden_elements);
		var len = hidden_elements.length;
		console.log(len);
	})
	</script>
</head>
<body>
	<div id="test">
		<br />
	</div>
</body>
</html>
Attachments (0)
Change History (12)

Changed October 02, 2011 11:42PM UTC by jen@littlegreenpixel.com comment:1

JSfiddle test case here: http://jsfiddle.net/DhddZ/

Changed October 07, 2011 12:40AM UTC by dmethvin comment:2

component: unfiledselector
priority: undecidedlow
status: newopen

Confirmed. I thought it might be due to <br /> elements having different heights in the browser but this shows they both return 0 for height:

http://jsfiddle.net/dmethvin/DhddZ/2/

Changed October 07, 2011 02:49PM UTC by timmywil comment:3

owner: → timmywil
status: openassigned

Sticking this here for future reference: http://jsfiddle.net/timmywil/DhddZ/6/

This offsetHeight during the selection is 19, but the offsetHeight during the height() check is 0 because it goes through swap, which applies display: block before checking because offsetWidth was 0. So, the different codepaths make sense now, but this is a pain.

Possible solution would be to check width === 0 OR height === 0, but there may be a reason why do both.

Changed October 22, 2012 05:43PM UTC by timmywil comment:4

milestone: None1.next
owner: timmywil
status: assignedopen

Changed January 21, 2013 10:13PM UTC by Timmy Willison comment:5

resolution: → fixed
status: openclosed

Treat elements as hidden when either offsetWidth OR offsetHeight is 0. Fixes #13132, #10406.

Changeset: 3015ee0b5a3cae399b53314bd9a859f61de3b94a

Changed January 21, 2013 10:13PM UTC by Timmy Willison comment:6

Treat an element as hidden if either offsetWidth or offsetHeight is 0. Fixes #13132, #10406.

Changeset: 372e04e78e81cc8eb868c5fc97f271a695569aa5

Changed January 21, 2013 11:04PM UTC by timmywil comment:7

For reference: http://jsbin.com/oduyax/1

Changed January 31, 2013 03:23AM UTC by timmywil comment:8

component: selectorcss
priority: lowhigh
resolution: fixed
status: closedreopened

Changed January 31, 2013 03:23AM UTC by timmywil comment:9

owner: → timmywil
status: reopenedassigned

Changed May 06, 2013 07:59PM UTC by timmywil comment:10

milestone: 1.next1.11/2.1

Changed December 16, 2013 06:52PM UTC by timmywil comment:11

milestone: 1.11/2.11.12/2.2

Changed July 18, 2014 12:32AM UTC by Timmy Willison comment:12

resolution: → fixed
status: assignedclosed

CSS: elements are hidden when either offsetWidth or offsetHeight is zero

  • Note: this is a breaking change that has been delayed for several versions.

Fixes #10406

Fixes #13132

Changeset: 10399ddcf8a239acc27bdec9231b996b178224d3