Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  150] [ 6]  / answers: 1 / hits: 24628  / 13 Years ago, fri, march 25, 2011, 12:00:00

I'm working on a project that uses the velocity templating system, so the $ character is reserved, and cannot be used in javascript variable names.



As such, I have to prefix jQuery variables and methods with jQuery, rather than $, e.g. jQuery(document).ready(function() {}); as opposed to $(document)ready(function(){});



This is ordinarily fine, but in this case I am using colorbox.



My code to call colorbox works fine, and looks like this:



jQuery(document).ready(function () {
jQuery(#addUser).colorbox({
href:add,
width:500px,
onClosed: function (message) {
dataTable.refresh(jQuery(#ajaxResult).text(message));
}
})

...
})


I have a link inside the colorbox that I want to attach the colorbox.close method to, but when I click the link, I get this error:




Uncaught TypeError: Cannot call method
'close' of undefined




This is my code:



jQuery(document).ready(function () {
jQuery(a).click(function() {
jQuery.colorbox.close(User added succesfully);
});

...
})


Can anybody tell me why I cannot close the colorbox?



By the way, the X that comes with colorbox still works to close it.


More From » jquery

 Answers
18

The easiest way to solve this for me was to store jQuery.colorbox as a variable in the global namespace. Yucky, but it works.



Here is what I put in the parent window:



jQuery(document).ready(function () {
colorbox = jQuery.colorbox;

...
})


Then this is how I call it:



jQuery(document).ready(function () {
jQuery(a).click(function() {
colorbox.close(User added succesfully);
});

...
})

[#93072] Thursday, March 24, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kristinsonjab

Total Points: 364
Total Questions: 98
Total Answers: 98

Location: Christmas Island
Member since Mon, Oct 19, 2020
4 Years ago
kristinsonjab questions
Fri, Mar 4, 22, 00:00, 2 Years ago
Fri, Jan 22, 21, 00:00, 3 Years ago
Fri, Aug 14, 20, 00:00, 4 Years ago
;