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 8299183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:04:09+00:00 2026-06-08T16:04:09+00:00

I am trying to test for an attribute in a dynamic php photo gallery

  • 0

I am trying to test for an attribute in a dynamic php photo gallery that loads images from a folder into a gallery. The gallery uses lightbox to display the photo once clicked. This is what I’m using to test:

if( $('#lightboxImage').attr('src') !== 'undefined'){ do something here }

I’m getting an initial error (Cannot call method ‘attr’ of null) in debug I think because the #lightboxImage only has a ‘src’ attribute when an image from the gallery is clicked. Nothing is obviously clicked when the page first loads.

Any ideas on how to solve this?

Thanks

  • 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-06-08T16:04:11+00:00Added an answer on June 8, 2026 at 4:04 pm

    I’m with @Malvolio, your error doesn’t quite add up. You should not be getting the error you’re describing. To wit:

    <img id="src" class="src" src="http://goo.gl/UohAz"><br/>
    <img class="src" src=""><br/>
    <img class="src">
    
    console.log($('#nothing').attr('src'));
    console.log($('#src').attr('src'));
    

    http://jsfiddle.net/7ZGwe/

    Running onload gives me:

    undefined
    http://goo.gl/UohAz
    

    So your actual problem has to do with something else, as Malvolio suggests. I can’t necessarily speculate any better than what Malvolio has, except maybe jQuery() should be tried in place of $().


    This is a little bit beside your underlying problem, but has to do with what you asked. Instead of doing a test, you could:

    [src]:not([src=""])
    

    http://jsfiddle.net/jSQ3P/3

    In your selector and bypass the check. So in other words:

    $('#lightboxImage[src]:not([src=""])').doStuff();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to test an AccountController that uses DotNetOpenAuth but I am running into
I am trying to remove the attribute xmlns=http://webdev2003.test.com from the following xml using xsl/xslt,
I'm trying to test if an attribute on an ancestor of an element not
I have a DataAnnotationValidator that I created. I am currently trying to test it
I've been trying to set my application up so that I can unit test
I am trying to test my views with RSpec. The particular view that is
I'm trying to do a little Test-First development, and I'm trying to verify that
I am trying to read attribute values from themes and styles which were designed
I'm trying to make a simple link that will toggle my status attribute in
Using TeamCity, I'm trying to get a (TestAutomationFX) test that requires an STA thread

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.