1

I can set a div to top and left position of a button using following code:

var p = $("#tag-add");
var offset = p.offset();
$("#TagModal").offset({ top: offset.top, left: offset.left})  

Output:

enter image description here

But I want to set the div to bottom right of button:

enter image description here

How to do this?

GorvGoyl
  • 42,508
  • 29
  • 229
  • 225

2 Answers2

2

Use this:

$("#TagModal").offset({
  top: offset.top + p.outerHeight(),
  right: offset.left + p.outerWidth()
});
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
2

Try with this:

var p = $("#tag-add");
var offset = p.offset();

var $modal = $("#TagModal");
$modal.offset({
  top: offset.top + p.outerHeight(),
  left: offset.left + p.outerWidth() - $modal.outerWidth()
});

(Subtract width of the modal from @PraveenKumar's example)

See this JSFiddle.

Arg0n
  • 8,283
  • 2
  • 21
  • 38
  • @JerryGoyal See update, you were setting `right` instead of `left`. Accutally, @PraveenKumar had changed it to `right` and i took the first template from his answer. – Arg0n Dec 14 '15 at 14:27