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

The Archive Base Latest Questions

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

I have to attach a jQuery to an invoice. Sometimes I have to print

  • 0

I have to attach a jQuery to an invoice. Sometimes I have to print multiple invoices as once in a batch. When this happens my exact same jQuery appears for every invoice and it runs each time creating extra elements I do not need. Is there a way to have a jQuery that appears more then once only run once when it is the last time it appears in the code? Thanks for any help.

Example is below. I have previously posted this and everyone asked to see how I was doing it. I was not sure how to add the code to the post as it said it was too long. Thanks for all your help. You guys are awesome.

<table width=180 border=0 cellpadding=0 cellspacing=0>
                <tr> 
                  <td class="barcode_needed">10133</td>
                </tr>

<!--This section of code is attached to every order so it repeats when each order prints, (this is a simplified version of the code, I need to make it only run the last time it shows up-->                    
<link rel="stylesheet" type="text/css" href="http://barcode-coder.com/css/style.css?ft=1298939919" />
<script type="text/javascript" src="http://barcode-coder.com/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="http://barcode-coder.com/js/jquery-ui-1.7.custom.min.js"></script>
<script type="text/javascript" src="http://barcode-coder.com/js/jquery-barcode-last.min.js"></script>


<script>
$('td.barcode_needed').append('<div class="bcTarget">');

$('.bcTarget').each(function() {
var $this = $(this);
$this.barcode(
    'G' + $this.closest('td.barcode_needed').text(),
    'code128'
);
});


</script>
<!--End Repeating Code-->
                <tr> 
                  <td class="barcode_needed">20133</td>
                </tr>


<link rel="stylesheet" type="text/css" href="http://barcode-coder.com/css/style.css?ft=1298939919" />
<script type="text/javascript" src="http://barcode-coder.com/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="http://barcode-coder.com/js/jquery-ui-1.7.custom.min.js"></script>
<script type="text/javascript" src="http://barcode-coder.com/js/jquery-barcode-last.min.js"></script>


<script>
$('td.barcode_needed').append('<div class="bcTarget">');

$('.bcTarget').each(function() {
var $this = $(this);
$this.barcode(
    'G' + $this.closest('td.barcode_needed').text(),
    'code128'
);
});


</script>

                <tr> 
                  <td class="barcode_needed">30133</td>
                </tr>


<link rel="stylesheet" type="text/css" href="http://barcode-coder.com/css/style.css?ft=1298939919" />
<script type="text/javascript" src="http://barcode-coder.com/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="http://barcode-coder.com/js/jquery-ui-1.7.custom.min.js"></script>
<script type="text/javascript" src="http://barcode-coder.com/js/jquery-barcode-last.min.js"></script>


<script>
$('td.barcode_needed').append('<div class="bcTarget">');

$('.bcTarget').each(function() {
var $this = $(this);
$this.barcode(
    'G' + $this.closest('td.barcode_needed').text(),
    'code128'
);
});


</script>

</table>
  • 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-23T00:43:50+00:00Added an answer on May 23, 2026 at 12:43 am

    Change your repeating template to include a check:

    <script>
    if (typeof alreadyDone === "undefined") {
       var alreadyDone = true;
    
       $(document).ready(function() {
         $('td.barcode_needed').append('<div class="bcTarget">');
    
         $('.bcTarget').each(function() {
           var $this = $(this);
           $this.barcode('G' + $this.closest('td.barcode_needed').text(),'code128');
         });    
       });
    }
    </script>
    

    Now it should run only once.

    Another thing to try, where we remove the classes as we go…

    <script>
     $('td.barcode_needed').each(function() {
           $(this).append('<div class="bcTarget">');
     });
    
     $('.bcTarget').each(function() {
       $(this).barcode('G' + $(this).closest('td.barcode_needed').text(),'code128');
       $(this).removeClass('bcTarget');       
       $(this).closest('td.barcode_needed').removeClass('barcode_needed');
     });    
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does jquery/javascript have any event model that you can attach to your objects? Basically
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
I have a question related to this one : I'm trying to attach an
I have CakePHP app in which I'd like to attach gallery to multiple resources.
I have a few jQuery click/hover events that attach to items in a list
I asked a similar question earlier How can I have jquery attach behavior to
I am trying to attach an image using jQuery but have gotten a strange
I have written a plugin with the following signature: jQuery.fn.attach = function(element, settings, duration,
I have an EditText and I want to attach to it a KeyListener that
I have searched inoformation to how attach local database to the IPA file to

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.