ColorBox is failing to load properly, even though all JavaScript code is being executed correctly

I've been attempting to implement a colorbox feature (triggered by clicking the 'sign me up' button), but it doesn't seem to work as expected. I have double-checked for any JavaScript errors or console errors, but everything appears fine without any issues. I have properly linked the stylesheet, JS file, and included the header script, all of which are loading correctly on the page.

<link rel="stylesheet" href="css/colorbox.css" />
<script src="js/jquery.colorbox.js"></script>
    <script>
      $(document).ready(function(){
        //Examples of how to assign the ColorBox event to elements
        $(".inline").colorbox({inline:true, width:"50%"});
        $(".callbacks").colorbox({
          onOpen:function(){ alert('onOpen: colorbox is about to open'); },
          onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
          onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
          onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
          onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
        });

        //Example of preserving a JavaScript event for inline calls.
        $("#click").click(function(){ 
          $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
          return false;
        });
      });
    </script>

I have set up the inline content div (which is initially hidden) and connected it to the button correctly.

<span class="btn"><a href="#inline_content">Sign Me Up!</a></span>

Below is the inline content:

<div style='display:none'>
  <div id='inline_content' style='padding:10px; background:#fff;'>
  <p><strong>This content comes from a hidden element on this page.</strong></p>
  <p>The inline option preserves bound JavaScript events and changes, and it puts the content back where it came from when it is closed.</p>
  </div>
</div>

View live site demo

Answer №1

Your code has some issues with the selectors. Here is an updated version of the code for you to try:

<span class="button"><a class="popup" href="#content">Click Me!</a></span> 

Include this jQuery script as well:

$(document).ready(function(){
    $(".popup").lightbox({
      inline:true,
      onOpen:function(){ alert('Opening lightbox'); },
      onLoad:function(){ alert('Loading content in lightbox'); },
      onComplete:function(){ alert('Content loaded in lightbox'); },
      onCleanup:function(){ alert('Closing lightbox'); },
      onClosed:function(){ alert('Lightbox closed'); }
    });
}); 

See a demo here: http://jsfiddle.net/b2yW8/

Answer №2

To enable the colorbox feature on a specific link, make sure to add the .inline class to that link.

<span class="btn"><a href="#inline_content" class="inline">Click Here</a></span>

Here is how you can set up the colorbox functionality:

$(document).ready(function(){
   $(".inline").colorbox({inline:true, width:"50%"});
});

You do not need all those callbacks for loading colorbox, so it's best to stick with the (.inline) method instead of the (.callbacks) one.

  • Chris

UPDATE:

Currently, your jQuery code is incorrect and causing issues:

    <script>
      $(document).ready(function(){
    $(".callbacks").colorbox({
      inline:true,
      onOpen:function(){ alert('onOpen: colorbox is about to open'); },
      onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
      onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
      onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
      onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
    });
}); <-- Extra closing tag
        }); <-- Extra closing tag

        //Example of preserving a JavaScript event for inline calls.
        $("#click").click(function(){ 
          $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
          return false;
        });
      });
    </script>

To simplify things and correct the errors, I suggest replacing the entire code block with this:

<script>
    $(document).ready(function(){
       $(".inline").colorbox({inline:true, width:"50%"});
    });
</script>

Add the class="inline" to your link, and everything should work smoothly =]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve XML data and convert it into a JavaScript array, then extract the values and display them

After searching for a while, I have come across similar solutions but not exactly what I need. I am attempting to transform this XML snippet: <?xml version="1.0"?> <document name="New Document"> <url>http://nsc-component.webs.com/Of ...

Is there a way to get Axios to display CSS on the page?

While working on a Web Viewer project with axios for web scraping practice, I encountered an issue where the CSS wasn't loading properly. Here is the code snippet I used: console.log("Tribble-Webviewer is starting!") const express = requir ...

Sending multiple parameters to ASP.NET Web Forms Web Method using jQuery AJAX

When calling a Web Method in the code behind with a Method Signature that accepts 4 or more strings, I create a params variable to store all the input fields I want to pass to the method. However, when attempting to pass "params" in my AJAX call, my curr ...

Using the Flex display property automatically adjusts the height of a button based on its

I have a main container, and within it, an <h1> heading and a <button>. I align them using justify content-between. Since the main container has a d-flex class, the button ends up having the same height as the main container. Is there a way to ...

Issue with IE due to jQuery/JavaScript conflict

After selecting one of the two radio buttons, I want to increment the total by $10. If the other option is selected, I want to revert back to the original total price. The jQuery function I am currently using is as follows: function check_ceu() { var ...

Deal with Ajax request only once

I am currently working with a table that displays rows, as shown in the image below. When the "order online" link is clicked, a form appears just below the respective row, similar to the second image. FIRST IMAGE SECOND IMAGE My current challenge invo ...

Creating a moving background for a loading bar with HTML5 and Shadow DOM is currently underway

Can anyone help with animating the progress bar using the HTML5 <progess> tag? I've been able to customize the Shadow DOM elements successfully, but I'm having trouble animating the background (repeating linear gradient). It seems to work i ...

Step-by-step guide on creating a concealed data variable within a table cell

Looking for a solution to update table cells via AJAX. Need to pass new info and previous cell's ID as hidden variable in query. Unsure on how to hide the ID data, similar to using a hidden input in a form. Any assistance is greatly appreciated. Thank ...

Troubleshooting Issues with Passing Values in jQuery AJAX POST Requests

Currently, I am working on two basic PHP pages: notification.php <html> <head><title></title> <meta charset="UTF-8"> <script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script> <script src="ht ...

Prevent Scrolling on Body with W3 CSS

While implementing scroll body lock packages like body-scroll-lock, react-scrolllock, or tua-body-scroll-lock alongside the W3 CSS package, I have encountered an issue where the body remains unlocked even when the designated element is active or open (e. ...

Tips on maintaining the original text hues that were established using setForeground() when a QTableWidgetItem is picked

Issue at Hand: Currently, when the first row is selected as shown in Figure 2 below, all text colors are changed to black, instead of maintaining their original style displayed in Figure 1. Is there a way to retain the original colors when a row is selec ...

The form control is lacking a specified name attribute, causing the value accessor to not be

Hi there! I am currently working on binding my slider to an attribute with values 1 and 0. When the value is 1, the switch should be active, and when it's 0, it shouldn't be. I have successfully bound some Input and Select Elements, but I encount ...

Troubleshooting: Inline Styles not displaying Background Div Images in Next.Js

I am currently attempting to display images in a component by using a map and an external JS file to store the images as objects. I then loop through them to set each one as a background image for every created div. However, it seems like my current implem ...

Unresponsive CssClass in Asp.net Webpage

Incorporating a MasterPage into my website structure, I've added various tabs in the header section of the MasterPage using the following C# code: <ul id="tabMenu"> <li><asp:HyperLink ID="homeLink" runat="server" o ...

jQuery - the power of concurrent execution

Looking to make multiple AJAX calls to the YouTube API to fetch video information in JSON format. The calls can be processed synchronously, but I want to ensure that the processing function is not triggered until all data is received. Currently using recu ...

What is causing the align content property to not function as expected in this situation?

Is it expected for the flex items of the .center-section-container to be closer together when using this property? They do not seem to be affected at all. I have applied flex wrap so the items are now in different lines but too far away from each other, I ...

.forEach returns an undefined value for each length

Having trouble with my if statement. It seems like the else block is working fine, but the if section is not functioning as expected. The variable count1 comes out as undefined. Interestingly, the conditions inside the if statement are working correctly ...

I possess a solitary div element that requires dynamic replication

I have a single container and an unspecified number of rows of data. I want to display this data on HTML cards that are generated dynamically based on the number of rows. For example, if there are 10 rows of data, I need to create 10 card elements with ea ...

Immediate family members nearby are not an option. We will have to create the form dynamically

On a previous page, there is a form that allows users to input data and define the number of "Attributes" they want to assign to a device by clicking on a button. Users are prompted to specify a name and type for each attribute. If the user selects "Selec ...

Centering bootstrap columns in a WordPress template

I am facing an issue with aligning columns in a bootstrap section within a Wordpress template that I am working on. The problem is that the columns on the second line of the row are not centered. Currently, the layout displays 4 columns in the top row and ...