Skip to main content

Bug Tracker

Side navigation

#8582 closed bug (duplicate)

Opened March 22, 2011 09:39AM UTC

Closed March 24, 2011 03:22PM UTC

Last modified April 05, 2011 06:16AM UTC

.focus() fires attribute events, but doesn't fire binded events

Reported by: albertbrufau@gmail.com Owned by:
Priority: undecided Milestone: 1.next
Component: unfiled Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:
Description

When a focus related event is binded to an element, it is fired when the element loses the focus via browser way (tab key, mouse click). But when it loses focus via .focus() to another element, it doesn't fire. However, if the event is defined on the attribute of the element, it fires in both cases.

I attach a complete test: Control1 fires change event when loses focus with mouse or tab key, but doesn't fire change event when pressing enter key (which executes a focus on #submitbutton). In the other hand, Control2 fires change event in both cases. I've tested this on jQuery 1.5.1 and 1.3.2 in the following browsers: Firefox 4, IE9 and Chrome, and there is the same issue.

<!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">
<head>
    <title>TESTING</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />        
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
	
	<script type="text/javascript" charset="UTF-8">
	/* <![CDATA[ */
	$(document).ready(function() {
		if ($.browser.mozilla) {
			$("input.data-entry").keypress (checkEnter);
		} else {
			$("input.data-entry").keydown (checkEnter);
		}
		$('#control1').bind('change', function(event){$('#result').html($(this).val());});
	});
	
	function checkEnter(event) {
	  if (event.keyCode == 13) {
		$('#submitbutton').focus();
		return false;
	  } 
	}
	/* ]]> */
	</script>
</head>
<body>
	<form action="/" method="get">
		<fieldset>
			<input type="text" id="control1" name="control1" value="control1" class="data-entry" tabindex="1" /><br />
			<input type="text" id="control2" name="control2" value="control2" class="data-entry" tabindex="2" onchange="$('#result').html($(this).val());"/><br />
			<div id="result">- - -</div><br />
			<input type="submit" id="submitbutton" />
		</fieldset>
	</form>
</body>
</html>
Attachments (0)
Change History (4)

Changed March 24, 2011 03:22PM UTC by dmethvin comment:1

resolution: → duplicate
status: newclosed

Changed March 24, 2011 03:22PM UTC by dmethvin comment:2

Duplicate of #7340.

Changed March 30, 2011 07:16PM UTC by anonymous comment:3

I think that isn't the same issue, because it also happens with jQuery 1.4.2 and all the other jQuery versions. It seems to be a similar bug, not the same.

http://jsfiddle.net/cwvLQ/

Changed April 05, 2011 06:16AM UTC by anonymous comment:4

Replying to [comment:2 dmethvin]:

Duplicate of #7340.

I think that isn't the same issue, because it also happens with jQuery 1.4.2 and all the other jQuery versions. It seems to be a similar bug, not the same.

http://jsfiddle.net/cwvLQ/