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

  • Home
  • SEARCH
  • 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 8215983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:58:28+00:00 2026-06-07T11:58:28+00:00

[ { link : images/examples/image-3.png, image : images/examples/image-3.png, title : copy }, { link

  • 0
[
    {
        "link"  : "images/examples/image-3.png", 
        "image" : "images/examples/image-3.png", 
        "title" : "copy"
    },
    {
        "link"  : "images/examples/image-3.png", 
        "video" : "video placeholder", 
        "title" : "copy"
    }               
]

In this example, I want to have a condition that says if this value is “video” do this else if value is “image” do this… but I seem to not be able to get handle of “video” or “image”.

This is my function:

$.getJSON("javascripts/media.json", function(data) {                            
    $("<ul class='gallery'></ul>").prependTo("#content");

    for (var i=0; i<data.length; i++) {
        var gallery = data[i];

        //alert(data[1]);
        if (gallery.image = true) {
            $(
            "<li class='image'>" +
                "<a class=\"imageLink\" href='" + gallery.link + "' rel=\"lightbox\">" + 
                    "<img src=" + gallery.image + " alt=" + gallery.title + ">" +
                "</a>"
            + "</li>").appendTo(".gallery");    
        }
        else if (gallery.video = true) {
            $(
            "<li class='video'>" +
                "<a class=\"videoLink\" href='" + gallery.link + "' rel=\"lightbox\">" + 
                    "<img src=" + gallery.video + " alt=" + gallery.title + ">" +
                "</a>"
            + "</li>").appendTo(".gallery");    
        }

    }
}).error(function() { alert("error"); });
  • 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-07T11:58:30+00:00Added an answer on June 7, 2026 at 11:58 am

    Just gallery.image and gallery.video without anything else in condition will fix it.

    Your first problem is that you use single = – assignment, not comparison that would be either == or ===. This making first (image) check always succeed and also overwrites image link you store in it with value true.

    And second, you don’t really need to compare anything with true unless you do strict === with real true value. Just use any truthy value in condition by itself.

    And last, you actually operate on object. As soon as jQuery decoded JSON for you, this no longer have anything to do with JSON.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a link of a picture like that: http://www.google.com/images/srpr/logo3w.png Can I retrieve
I have third party sites that link to some images on my site. The
I have url like this which is a js file example like this link
I checked this link of S.O : Pop Images like Google Images And tried
I am trying to model this relationship following this link http://www.javaworld.com/javaworld/jw-01-2008/images/datamodel.gif Its the usual
I can't seem to generate a image button or action link that will go
I have images of various formats (.png, .jpg, .bmp, etc.) stored as compressed text
How to link HTML string loaded from sqlite db with images stored in bundle
I am trying to create sliding images effect: Online demo link text . The
Upon clicking on a link, I am bringing in some images from a JSON

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.