Bug Tracker

Opened 10 years ago

Closed 9 years ago

#6508 closed bug (invalid)

Inadvertent change event firing on IE8

Reported by: sharo Owned by:
Priority: undecided Milestone: 1.4.3
Component: event Version: 1.4.2
Keywords: onchange, live, event Cc:
Blocked by: Blocking:

Description

I have found a scenario where the live function causes a re-firing of events on an unrelated element. I have put a sample page that shows this problem below.

It is quite simple to reproduce. First create two select elements. On Select1 place an inline onchange handler that simply does "alert('select1')".

On select2, add a class= "select2". Then use the live function to bind the change event to the select2 class: $(".select2").live("change", function(){ alert("select2");})

As you change the value of each select, you would expect an alert to fire once each time the value changes on either select.

However if you change the value of select1 you will see two alerts.

If you give the live function a context this problem goes away.

############################### # Sample Code ###############################

<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<script>
  $(function()
  {
  $(".livecaller").live('change', function() { alert(1);});
  });
</script>
</head>
<body>
<form action="#">
  <select onchange="alert(0);">
    <option val="1">1</option>
    <option val="2">2</option>
    <option val="3">3</option>
  </select>
  <div id="foobar">
  <select class="livecaller">
    <option val="1">1</option>
    <option val="2">2</option>
    <option val="3">3</option>
  </select>
  </div>
  
  <input type=submit />
</form>
  
</body>
</html>

Change History (1)

comment:1 Changed 9 years ago by addyosmani

need: ReviewTest Case
Priority: undecided
Resolution: invalid
Status: newclosed

Tested in IE 7, 8 and 9. I haven't experienced multiple alerts when selecting 'select1' in either of these.

Please re-submit with more details of the problem or with an alternative test case.

Note: See TracTickets for help on using tickets.