0

Some code that is not working as expected has the following:

$('#' + myId).center();

This code is not working properly. The odd part is that I cannot find .center() documented in jQuery or javascript. It is not a function in our code either.

The code "kind of works". It centers the div on the page, but only if the width of the browser is smaller than a threshold. Otherwise, it positions it unexpectedly.

Most likely this code was added by a developer who found something about it online. However, I cannot find anything. Is this a deprecated method?

I should add that the objective is the center an absolutely positioned div in the viewport. That is, the user has scrolled to the bottom of the page, clicks a button, a popup shows, but it needs to be centered in the currently viewed part of the screen.

Jeffrey Simon
  • 702
  • 2
  • 9
  • 19
  • 2
    https://stackoverflow.com/questions/210717/using-jquery-to-center-a-div-on-the-screen#210733 quick google. It's not a core jQuery method. – Taplar May 22 '19 at 17:33
  • 1
    But whether or not this is what your function is, we have no way of knowing. You should search your code base for `.fn.center` – Taplar May 22 '19 at 17:33
  • `.position("center")`? – Aravind Suresh May 22 '19 at 17:35
  • If you use an IDE you should be able to have it track the function call back to it's definition, typically by holding the control key and clicking on the function name. – DrCord May 22 '19 at 17:38
  • @Taplar - I did find the definition for fn.center - I was not searching properly. – Jeffrey Simon May 22 '19 at 18:10
  • @Aravind Suresh - I did find documentation at https://api.jqueryui.com/position/. However, it is not working for me properly. Not sure why. – Jeffrey Simon May 22 '19 at 18:10
  • @Taplar - since the solution to the issue was triggered by your second comment about fn.center, if you make it into an answer I will select it as the answer. – Jeffrey Simon May 24 '19 at 18:36

0 Answers0