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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:16:20+00:00 2026-05-27T02:16:20+00:00

I have following function to add elements to the page on the fly; function

  • 0

I have following function to add elements to the page on the fly;

function modalConfirm (title, msgBody, btnOK, btnCancel) {
    element = '<div class="ui-modal-widget"><div class="confirm"><h2>'+title+'</h2><div>'+msgBody+'</div></div>';
    element += '<div class="button-panel" style="float:right; margin-top:-30px; margin-right:5px;">';
    element += '<a href="#" rel="closeModal">'+btnCancel+'</a>';
    element += '<a href="#" rel="confirmModal">'+btnOK+'</a>';
    element += '</div></div>';
    // OPEN MODAL WINDOW

I’m calling the function above when $('a.checkData') is clicked.

PROBLEM


Everything seems working fine except, if I close the opened modal window by clicking $('a[rel=closeModal]') more than once and after that few times click $('a[rel=confirmModal]') it is doing the same actions as many times as I clicked $('a[rel=closeModal]').

Example;

$('a[rel=closeModal]').live('click', function(e) {
e.preventDefault();
// CLOSE MODAL BOX
});

$('a[rel=confirmModal]').live('click', function(e) {
e.preventDefault();
console.log('Modal Is Confirmed');
});

Consider the code above. When $('a.checkData') is clicked and user clicks $('a[rel=closeModal]') 5 times before clicking $('a[rel=confirmModal]'). It will write 5 times Modal Is Confirmed for 1 click. If user clicks $('a[rel=closeModal]') 10 times before clicking $('a[rel=confirmModal]'). It will write 10 times Modal Is Confirmed.

I will be glad if you could help me out with this problem. I tried to add $('a[rel=confirmModal]').unbind('click'); literally everywhere (inside the function, before calling the function, after calling the function just before / after / inside of the $('a[rel=confirmModal]').live('click',function(){}); without any success.

Thank you for your time and concern in advance.

  • 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-27T02:16:20+00:00Added an answer on May 27, 2026 at 2:16 am

    You need to consider using jQuery delegate() and jQuery undelegate()

    This is very similar to live however you can choose whether or not to bind to the document body or to a relative parent of the future added element.

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

Sidebar

Related Questions

I have run the following through JSLint: $(document).ready(function() { /* Add paragraph on page
I have following calss to validate my input elements. class Validator_FormValidator { public function
If I have following in jQuery $(#someId).add(#someOtherId).bind(click, function(e) {... I get the click bound
I have the following bit of code, simply: $(function() { $('a.add-photos-link').live('click', function(e) { $(this).colorbox({
I have a strange one. Create a new form. Then add the following function
I have the following Javascript code add_num = { f: function(html, num) { alert(this.page);
I have the following function that hide s a certain div when I click
I have the following function that checks/unchecks all checkboxes on the page by selecting
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
I have the following function that is pulling data from a database. The ajax

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.