AlteredConcept
AlteredConcept

Reputation: 2632

Positioning JQuery UI Dialog near clicked link

I have the following jquery function for some links

$(".clickable").click(function(event){
     // load dialog content...
     $("#dialog").dialog();
     return false;
   });

What i'd like to do is have JQuery's UI dialog display near the clicked link. Is there any way to do this using just JQuery.

Thanks!

Upvotes: 2

Views: 2289

Answers (1)

Christian C. Salvadó
Christian C. Salvadó

Reputation: 827416

You could use the event.clientX and event.clientY properties, to get the coordinates where the click event was fired, and move the dialog to them:

$(".clickable").click(function (e) {
  // open and move the dialog
  $("#dialog").dialog('open').dialog('option', 'position',[e.clientX,e.clientY]);
  return false;
});

Check the above example here.

Upvotes: 5

Related Questions