JavaScript Removing and readding an element pushes another element down, toggling the float in dev tools causes the element to move back to the correct position

I have a container that holds three items. One is floated left, another is centered and the last is floated right. If I remove the center item and add it back the right most item gets pushed down and I don't know why.

If you select the right item and view it in Chrome dev tools you can toggle the float: right off/on and then it will be positioned correctly.

This happens in Chrome but does not happen in FireFox. (I have not tested in IE)

I have a demo of the issue here: http://codepen.io/anon/pen/rVyRmy?editors=001

var on = true;
var l = $('<div class="left"></div>');
var r = $('<div class="right"></div>');
var clicky = function() {
  if (on) {
    $('.container').empty();
    $('.container').append(l);
    $('.container').append($(
      '<div class="fill">' +
      '<span>text</span>' +
      '<span>text</span>' +
      '<span>text</span>' +
      '<span>text</span>' +
      '</div>'
    ));
    $('.container').append(r);
    on = false;
  } else {
    $('.container').empty();
    $('.container').append(l);
    $('.container').append($('<input type="text" />'));
    $('.container').append(r);
    on = true;
  }
  $('.right').on('click', clicky);
};

$('.right').on('click', clicky);
.container {
  width: 400px;
  height: 20px;
  text-align: center;
  background-color: lightgray;
}
.left, .right {
  display: inline-block;
  width: 14px;
}

.left {
  position: relative;
  float: left;
}

.left:before {
  position: absolute;
  top: 4px;
  left: 4px;
  content: "";
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 5px 8.7px 5px 0;
  border-color: transparent orange transparent transparent;
}

.right {
  position: relative;
  float: right;
}

.right:before {
  position: absolute;
  top: 4px;
  right: 4px;
  content: "";
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 5px 0 5px 8.7px;
  border-color: transparent transparent      transparent orange;
}

span {
  width: 93px;
  background-color: green;
  display: block;
  float: left;
}
div span:first-child {
  margin-left: 14px;
}
<div class="container">
  <div class="left"></div>
  <input type="text" />
  <div class="right"></div>
</div>
Answer:1

I have made a JS/HTML5 game which is controlled by keyboard, I like to make it embeddable like flash games, but when I embed it inside an iframe it only capture keyboard events when iframe is focused. ...

I have made a JS/HTML5 game which is controlled by keyboard, I like to make it embeddable like flash games, but when I embed it inside an iframe it only capture keyboard events when iframe is focused. ...

  1. iframe capture keyboard events
  2. iframe keyboard capture

Bit of background, this comes from a submitted form that I used serializeArray() on I have a list of objects like so. [ {name: 0, value: 'waffles'}, {name: 0, value: 'pancakes'}, {name: 0, ...

Bit of background, this comes from a submitted form that I used serializeArray() on I have a list of objects like so. [ {name: 0, value: 'waffles'}, {name: 0, value: 'pancakes'}, {name: 0, ...

I have a checkbox section that users can select to add features. I need each input's value to add to a sum to be presented in the #payment-total and #payment-rebill section. Essentially, if they ...

I have a checkbox section that users can select to add features. I need each input's value to add to a sum to be presented in the #payment-total and #payment-rebill section. Essentially, if they ...

  1. javascript checkbox checked event
  2. javascript checkbox checked value
  3. javascript checkbox checked or not
  4. javascript checkbox checked onclick
  5. javascript checkbox checked not working
  6. javascript checkbox checked and unchecked event
  7. javascript checkbox checked event listener
  8. javascript checkbox checked unchecked
  9. javascript checkbox checked jquery
  10. javascript checkbox checked value push array
  11. javascript checkbox checked event example
  12. javascript checkbox checked undefined
  13. javascript checkbox checked check
  14. javascript checkbox checked default
  15. javascript checkbox checked returns undefined
  16. javascript checkbox checked function
  17. javascript checkbox checked condition
  18. javascript checkbox checked count
  19. javascript checkbox checked true false
  20. javascript checkbox checked state

I'm learning Ajax and I'm confused about something. In a tutorial, these two lines are included document.myForm.time.value = ajaxRequest.responseText; //code <form name='myForm'> Name: <...

I'm learning Ajax and I'm confused about something. In a tutorial, these two lines are included document.myForm.time.value = ajaxRequest.responseText; //code <form name='myForm'> Name: <...