JavaScript How to stick two unrelated elements together?

I'm working on an interface and I require something that would stick two unrelated elements together. Well, the most important element will be the "boss" and the other element called "employee" will follow the "boss" around and will change it's position accordingly.

This is the markup:

<div class="boss"></div>
<div class="employee"></div>
<div class="boss"></div>
<div class="employee"></div>
<div class="boss"></div>
<div class="employee"></div>
<div class="boss"></div>
<div class="employee"></div>

This is the jQuery I wrote:

$('.boss').each(function( i, obj ){

        var Pos = $(this).position();
        var ModuleWidth = $(this).outerWidth();

        $(this).next('.employee').position({
                my: 'right top',
                at: 'right top',
                of: $(this)
        });

});

So I'm iterating through all the .boss classes and aligning all .employees to the right top of boss. They are supposed to always stick. But if I edit the html from the boss within chrome Developer Tools the .boss element will become smaller and larger and the .employee will not re-position its self accordingly. I would like to make .employee always reposition its self.

Later Update:

This http://screencast.com/t/F0RO7ODF is the kind of behavior i'm looking for. The gray box is the BOSS and the orange box is the EMPLOYEE. These 2 element's have a wrapper and i'm actually moving the wrapper. But i'd like a solution without a wrapper. Note: The organge box's position is irelevant.

Answer:1

How to avoid of declaration all scripts together in index.html? How to load scripts only if they're necessary? Should I use RequireJs to solve this problem? Same problem with angular.module ...

How to avoid of declaration all scripts together in index.html? How to load scripts only if they're necessary? Should I use RequireJs to solve this problem? Same problem with angular.module ...

I have a small program, when you click on an "entry", the editing mode is opened, and the entry is to edit locked for others. There is every 10 seconds sends an ajax request to update the timestamp in ...

I have a small program, when you click on an "entry", the editing mode is opened, and the entry is to edit locked for others. There is every 10 seconds sends an ajax request to update the timestamp in ...

  1. javascript multiple intervals
  2. js multiple intervals
  3. javascript multiple set intervals
  4. javascript clear multiple intervals
  5. js clear multiple intervals
  6. js set multiple intervals

I have been reading about revealing module pattern in Addy Osmani's book. It highlights following disadvantage: A disadvantage of this pattern is that if a private function refers to a public ...

I have been reading about revealing module pattern in Addy Osmani's book. It highlights following disadvantage: A disadvantage of this pattern is that if a private function refers to a public ...

  1. javascript revealing module pattern
  2. javascript revealing module pattern constructor
  3. javascript revealing module pattern with parameters
  4. javascript revealing module
  5. javascript revealing module pattern multiple instances
  6. javascript revealing module pattern es6
  7. javascript revealing module pattern vs prototype
  8. javascript revealing module pattern inheritance
  9. javascript revealing module pattern nested namespace
  10. javascript revealing module pattern events
  11. javascript revealing module pattern tutorial
  12. javascript revealing module pattern public variables
  13. js revealing module pattern
  14. javascript self revealing module pattern
  15. node js revealing module pattern
  16. javascript module vs revealing module

I have following html form: <form method="POST" action="uploadImage" enctype="multipart/form-data"> <input type="file" class="file" name="file"/> ...

I have following html form: <form method="POST" action="uploadImage" enctype="multipart/form-data"> <input type="file" class="file" name="file"/> ...