views:

104

answers:

2

Hi Folks

I'm using a jQuery.Center() plugin that I found at Andreas Lagerkvist's website.

I have a control on the page called "divClipboard" that I want to appear in the middle of the screen when the user clicks a link.

I call the function

$('#divClipboard').center();

and it throws an error, the message being

$("#divClipboard").center is not a function

I think it's worth mentioning that I've tried specifying

jQuery.noConflict();
jQuery('#divClipboard').center();

and I've also renamed center() to centerElement() to no avail.

Our setup has 2 sites pointing at the same virtual directory, each accessed by a different URL. This plugin has always worked for me, until yesterday on one site (it even works on the other site on the same virtual directory).

Does anyone have any idea what could be wrong?

Thanks

Dave

A: 

Have you made sure that jQuery is loaded and then the plugin? Make sure also that your .center() call is in a jQuery loaded wrapper function

jQuery(function(){
  jQuery('#myClickableElement').click(function(){
    jQuery('#divClipboard').center();
  });
});
danrichardson
yeah, i'm certain of this because I included the plugin code as part of the same file that the jQuery code exists in. Everything exists inside the document.ready() function, and this function call is part of an event handler on an <a/> tag. It is definitely correct because it works everywhere else, except for this site. I think something is wrong outside the scope of the code, but I have no idea what it could be.
DaveDev
A: 

It turns out that the reason this was happening is because (as I've mentioned), we have 2 sites, and each site has slightly different content.

Site A works fine, but Site B is broken. This is because Site A uses a wrapper that doesn't have a reference to a jQuery file. Site B does have a reference. So, because I kept my center() code in the our jquery file, and Site B's wrapper also provided jQuery code, my jQuery code never got referenced.

The solution? put my center() pluggin in its own file!

DaveDev