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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:59:59+00:00 2026-05-23T00:59:59+00:00

I have a script that generates img tags, and i want to make sure

  • 0

I have a script that generates img tags, and i want to make sure the same img isn’t being made twice. This is the script i tried to create:

var included = 0;
var src = "";

jQuery.fn.checkCard = function() {
    if ($("#L_S_Inner").find($('img').attr(src))){
        included = 0;
    } else {
        included = 1;
    }
}

However it doesn’t work. Not sure what i’m doing wrong here…

It’s framed this way so that i can just check the variable ‘included’ in my img creation script.

EDIT

Added the img creation script:

$('#Results a').live('dblclick', function() {
    src = $(this).attr('href');
    getC = $(this).attr('class');
    checkCard();

    if (!(checkCard)) {
            $(this).parent().append($('<img />', {'src': src, 'class': 'DCT ' + getC + ''}));
    }
});
  • 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-23T01:00:00+00:00Added an answer on May 23, 2026 at 1:00 am

    Several problems here. First off, despite your explanation, I don’t see the need for the global variable. It’s ugly and dangerous practice – it should be the return value of the function, unless you have damned good reasons not to do it that way.

    Second, the as @sosborn says, the function does not have an input parameter – the src is either another global (that you haven’t shown), or the code just can’t work.

    Next, inside find there should be a selector, not a jQuery object, and inside attr there should be an attribute name (thus, a string "src"), not a value (presumably src contains something like http://...).

    Also, why make it into a jQuery plugin?

    Literal solution of the problem, I’d do this way:

    var checkCard = function(src) {
        return !!($('#L_S_Inner img[src="' + src + '"]').length);
    }
    

    A better yet solution is to remember what images you create by tracking them manually – much faster.

    var included = [];
    // ...
    // when you make an image
    included[src] = true;
    // ...
    // when you want to know if it is there
    if (included.hasOwnProperty(src)) // ...
    

    UPDATE: With the creation code posted, let me rewrite the second solution:

    var included = [];
    $('#Results a').live('dblclick', function() {
        var src = $(this).attr('href');
        var getC = $(this).attr('class');
    
        if (!included.hasOwnProperty(src)) {
            $(this).parent().append($('<img />', {'src': src, 'class': 'DCT ' + getC + ''}));
            included[src] = true;
        }
    });
    

    By the way, notice the vars I added to your inner variables. Declare your variables, it’s good for health.

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

Sidebar

Related Questions

I have a php script that randomly generates an image. Something like this: <?php
I have a script that generates DDL scripts to define materialized views for a
I have a script that generates images from text using PHP. It's working fine
I have a script that generates two lines as output each time. I'm really
I have an script that receives an encrypted url and from that generates a
For automated testing (using Hudson) I have a script that generates a bunch of
I have a Ruby script that generates a UTF8 CSV file remotely in a
I have a script that takes a table name and generates a control file
I have a datalist being generated with ASP, but unfortunately the jQuery script that
I have a script that generates an SQL query as text e.g. ... return

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.