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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:20:43+00:00 2026-06-12T17:20:43+00:00

Code : $(document).ready(function(){ $(#main_div).bind(‘click’, function(e){ var x = event.pageX-document.getElementById(main_div).offsetLeft; var y = event.pageY-document.getElementById(main_div).offsetTop; if(…)

  • 0

Code :

    $(document).ready(function(){
    $("#main_div").bind('click', function(e){
    var x = event.pageX-document.getElementById("main_div").offsetLeft;
    var y = event.pageY-document.getElementById("main_div").offsetTop;


    if(...)
    {
    $("#container-5").css({"top":y,"left":x});
    $(this).unbind('click');
    e.stopPropagation();

    }
    else if(...)
    {

    ....

    });
 });

When i click on main_div it checks for if function and proceeds. Css of container-5 is changed too. Now once the css is changed i don’t want it to keep changing on main_div clicks. So i tried $(this).unbind('click'); But this doesnt help because i want main_div to be clicked as many times as i want so that i can perform other functionalities. Help really appreciated.

  • 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-12T17:20:44+00:00Added an answer on June 12, 2026 at 5:20 pm

    Just add an additional if statement inside the callback function that will be true the very first time and false forever afterwards:

    var hasBeenClicked = false;
    $("#main_div").bind('click', function(e){
        if(!hasBeenClicked){
            hasBeenClicked = true;
            ...
            //the rest of your code
            ...
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code: $(document).ready(function() { $(#main_div).bind('click', function(e){ var x = event.pageX-document.getElementById(main_div).scrollLeft; var y = event.pageY-document.getElementById(main_div).scrollTop; document.pointform.form_x.value
I have a code like this $(document).ready(function(){ $(.add).bind ('click', function () { $('.main').append('<div class=add>Add
I have this code right now: $(document).ready(function () { $(div#main-edit).click( function() { var cursorExists
Here my code: $(document).ready(function() { $('#mid_select').live('click', function(e){ $('#middle').load( $(this).attr('href') + ' #middle'); var page
jQuery code add new virtual object .add to object .main $(document).ready(function(){ $('.main').on('click', '.add', function
I have a JS code like this <script type=text/javascript> $(document).ready(function(){ $('.main').on('click', '.block', function (){
On document ready I run this code: jQuery(document).ready(function(){ jQuery('#button').click(function() { jQuery('#contact_form').load(/Users/mge/Downloads/jquery-ajax-1/readme.txt); return false; });
jQuery Code: $(document).ready(function(){ $.getJSON('dat.js', function(data) { var obj = JSON.parse(data); alert(obj[0].title); }); }); My
Consider the following code: $(document).ready(function() { $(body).append(<div class='outer'><span class='inner'>Click me</span></div>); $(html).click(function(event) { var targetClass
Here is my code: $(document).ready(function(){ //These variables are for loading more posts var create_ptr

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.