JavaScript Place element inside other element using absolute. Elements are siblings place element inside div,jquery place element inside div,javascript

I am trying to place an element, "inner", flush against the upper right hand corner of another div, "outer", using absolute positioning. The "inner" element is not a child of "outer". I therefore need to look up the positioning of "outer" using js and use that.

However, it's not coming out quite right:

EDIT: it's not possible for me to reset the margin/padding/relative of the body div. There are other elements inside body.

http://jsfiddle.net/BZBSF/1/

#wrapper{background:red;
         width:100px;
         height:100px;}

#inner{
    position:absolute;
    background:green;
    width:50px;
    height:100px;
    margin:0;padding:0;
}

#body{position:relative;}

<div id = "body">
    <div id = "wrapper"></div>
    <div id = "inner"></div>    
</div>

var rect = document.getElementById("wrapper").getBoundingClientRect();

$("#inner").css({ 'top': String($(window).scrollTop()+rect.top)+"px" });

width_inner = $("#inner").width();

$("#inner").css({ 'left': String($(window).scrollLeft()+rect.right-width_inner)+"px" });
Answer:1

Is this what you want?

var rect = $('#wrapper');

$("#inner").css({ 'top': rect.position().top+"px" });

$("#inner").css({ 'left': (rect.position().left + rect.width() - $('#inner').width())+"px" });

http://jsfiddle.net/araSp/2/

And if you need to worry about padding/borders, you can use:

.innerWidth()

.outerWidth()

Answer:2

Just do a quick reset on the top:

* {
    margin:0;
    padding:0;
}

Fiddle

Note: This is a quick reset. You might want to use other reset stylesheets out there.

Answer:3

How do I create a image map with separate <select>? I need something like this: <img src="image.png" alt="Website map" usemap="#mapname" /> <map name="judete" id="judete"> <...

How do I create a image map with separate <select>? I need something like this: <img src="image.png" alt="Website map" usemap="#mapname" /> <map name="judete" id="judete"> <...

  1. image with select option
  2. change image with select option
  3. image select
  4. image select sticker instagram
  5. image select sticker instagram missing
  6. image select html
  7. image select bootstrap
  8. image select jquery
  9. image select css
  10. image select sticker instagram android
  11. image select instagram story
  12. image select box
  13. image select checkbox
  14. image select sticker
  15. image select js
  16. image select from gallery android
  17. image select react
  18. image select javascript
  19. image select dropdown
  20. image select underwood

Very simple example: var a = { id: 5 }; var b = { id: 6 }; var c = { id: 7 }; var arr = [a, b, c]; Now i have a function: function remove(startIndex) { // set objects to null from startIndex in ...

Very simple example: var a = { id: 5 }; var b = { id: 6 }; var c = { id: 7 }; var arr = [a, b, c]; Now i have a function: function remove(startIndex) { // set objects to null from startIndex in ...

  1. access via null object reference
  2. access vba is null object required

<ul class="todo-list"> <li ng-repeat="todo in todos">{{todo.todoContent}}<span class="pull-right glyphicon glyphicon-check" ng-class="{checked:todo.done}" ng-click="todoCheck(todo)" ...

<ul class="todo-list"> <li ng-repeat="todo in todos">{{todo.todoContent}}<span class="pull-right glyphicon glyphicon-check" ng-class="{checked:todo.done}" ng-click="todoCheck(todo)" ...

  1. change target attribute jquery
  2. change target attribute javascript
  3. setattribute target _blank
  4. set attribute target
  5. set target attribute in javascript
  6. set target attribute in jquery
  7. set target attribute html

When I load a jQuery multi-page the #hashed inner-page links work only after I refresh the page. I.e. http://value.holiday/go/to/United_States_of_America/Albuquerque Clicking directly on the image ...

When I load a jQuery multi-page the #hashed inner-page links work only after I refresh the page. I.e. http://value.holiday/go/to/United_States_of_America/Albuquerque Clicking directly on the image ...