Bug Tracker

Opened 8 years ago

Closed 5 years ago

#10406 closed bug (fixed)

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

Reported by: jen@… 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>

Change History (12)

comment:1 Changed 8 years ago by jen@…

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

comment:2 Changed 8 years ago by dmethvin

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/

comment:3 Changed 8 years ago by timmywil

Owner: set to 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.

comment:4 Changed 7 years ago by timmywil

Milestone: None1.next
Owner: timmywil deleted
Status: assignedopen

comment:5 Changed 7 years ago by Timmy Willison

Resolution: fixed
Status: openclosed

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

Changeset: 3015ee0b5a3cae399b53314bd9a859f61de3b94a

comment:6 Changed 7 years ago by Timmy Willison

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

Changeset: 372e04e78e81cc8eb868c5fc97f271a695569aa5

comment:7 Changed 7 years ago by timmywil

comment:8 Changed 7 years ago by timmywil

Component: selectorcss
Priority: lowhigh
Resolution: fixed
Status: closedreopened

comment:9 Changed 7 years ago by timmywil

Owner: set to timmywil
Status: reopenedassigned

comment:10 Changed 6 years ago by timmywil

Milestone: 1.next1.11/2.1

comment:11 Changed 6 years ago by timmywil

Milestone: 1.11/2.11.12/2.2

comment:12 Changed 5 years ago by Timmy Willison

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

Note: See TracTickets for help on using tickets.