Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6177503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:17:17+00:00 2026-05-24T00:17:17+00:00

I’m making a lightbox plugin called WowBox. Right now, if you want to make

  • 0

I’m making a lightbox plugin called WowBox.

Right now, if you want to make a div pop up you use this:

<a href="#element" rel="wowbox" title="Title">Open #element in WowBox</a>

And to make an image pop up you use this:

<a href="image.jpg" rel="wowbox[img]" title="Caption">Open image in WowBox</a>

Now, here is the the jQuery for it:

<script type="text/javascript">
  // Copyright © 2011 Nathan Johnson. All Rights Reserved.

  jQuery.fn.center = function() {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.height()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.width()) / 2) + $(window).scrollLeft() + "px");
    return this;
  }
  jQuery.fn.close = function() {
      $(this).click(function() {
      $('#lb-caption').slideUp(700);
      $('#lb-title').slideUp(700);
      $('#lightbox-container').fadeOut(600);
      $('#lightbox-overlay').delay(100).fadeOut(600);
      });
      }
    function ImgError(source){
    var errorMssg = "<div style='color:red;text-align:center;'>Error: The requested image wasn\'t found.</div>";
    $(this).hide();
    $('#lb-caption').hide();
    $('#lb-content').html(errorMssg);
    return true;
}

    $(document).ready(function() {
    $('#lightbox-container').center();
    window.onresize = function(event) {
    $('#lightbox-container').center();
    }

    $(document.createElement("div")).attr("id","lightbox-holder").prependTo("body"); 
    //The HTML of WowBox will be placed right after the starting <body> tag once the page is loaded.
    $('#lightbox-holder').html(' \
    <div id="lightbox-overlay"></div> \
    <div id="lightbox-container"> \
    <div id="lb-title"></div> \
    <div id="lightbox"> \
    <div id="close-lb"></div> \
    <div id="lb-content"></div> \
    </div> \
    <div id="lb-caption"></div> \
    </div>');
    $('a[rel="wowbox"]').click(function() {
    var element = $(this).attr('href');
    var content = $(element).html();
    var title = $(this).attr('title');
    var lightboxContainer = "'#lightbox-container'";
    $('#lb-content').ready(function() {
        $('#lightbox-container').center();
      });
    $('#lightbox-overlay').fadeIn(700);
    $('#lightbox-container').center().delay(100).fadeIn(700);
    $('#lb-caption').html('');
    $('#lb-content').html(content);
    $('#lb-title').html(title).fadeIn(700);
    return false;
  });
  $('a[rel="wowbox[img]"]').click(function() {
    var src = $(this).attr('href');
    var caption = $(this).attr('title');
    var lightboxContainer = "'#lightbox-container'";
    var content = "'#lb-content'";
    $('#lightbox-container').center();
    $('#lightbox-overlay').fadeIn(700);
    $('#lightbox-container').delay(100).fadeIn(700);
    $('#lb-title').html('').show();
    $('#lb-content').html('<img onload="$('+lightboxContainer+').center();" src="'+src+'" onerror="ImgError(this)" onmousedown="return false;" /><div onmousedown="return false;" id="image-cover"></div>');
    $('#lb-caption').html(caption).fadeIn(700);
    return false;
  });
      $('#close-lb').click(function() {
      $('#lb-caption').slideUp(700);
      $('#lb-title').slideUp(700);
      $('#lightbox-container').fadeOut(600);
      $('#lightbox-overlay').delay(100).fadeOut(600);
      });
      $(document).keypress(function(event) {
      if (event.keyCode == 27) {
      $('#lb-caption').slideUp(700);
      $('#lb-title').slideUp(700);
      $('#lightbox-container').fadeOut(600);
      $('#lightbox-overlay').delay(100).fadeOut(600);
    }
      });
  });
  </script>

Now I just need a way to detect if the href of the a tag is an image or a div. So I can just use $('a[rel="wowbox"]').click() instead of using both. I know this is probably going to contain an if/else statement, but if anyone help, that would be great. Thanks! 🙂

Kind regards,
Nathan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:17:18+00:00Added an answer on May 24, 2026 at 12:17 am
    if($(this).attr('href').indexOf('.jpg') > 0) // or any other extension
    {
        //do what you want
    }
    

    you can also go the other way around:

    if(!$(this).attr('href').indexOf('#') >= 0) // or any other extension
        {
            //do what you want
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.