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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:06:52+00:00 2026-06-14T13:06:52+00:00

<div id=element1 onclick=func();>1</div> <div id=element2 onclick=func();>2</div> <div id=element3 onclick=func();>3</div> <div id=element4 onclick=func();>4</div> <div id=element5

  • 0
<div id="element1" onclick="func();">1</div>
<div id="element2" onclick="func();">2</div>
<div id="element3" onclick="func();">3</div>
<div id="element4" onclick="func();">4</div>
<div id="element5" onclick="func();">5</div>
<div id="element6" onclick="func();">6</div>
<div id="element7" onclick="func();">7</div>
<div id="element8" onclick="func();">8</div>

When user click any div, func() function will work and a counter calculate how many times process func() function. For example 2 times (we determine the number) process func() function than when user click any div again function will not work. How can I do this with jquery?

  • 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-14T13:06:54+00:00Added an answer on June 14, 2026 at 1:06 pm

    Use a global variable to track the number of times the function is called.

    var counter = 0;
    
    function func() {
    
        counter++;
        if (counter > 2) return;
    
        // do other fn stuff
    }
    

    On a slightly related note, there is a better way of binding multiple click handlers when using jQuery:

    $('div[id^="element"]').click( func );
    

    Of course, it doesn’t really matter since return will halt execution, but if you didn’t want func to be called at all (i.e. if you wanted to remove the click event altogether), you could then simply do (if you make the change above):

    $('div[id^="element"]').unbind('click');
    

    This would be in place of the return statement in the first section of code.

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

Sidebar

Related Questions

<div id=element1 onclick=add();>10</div> <div id=element2 onclick=add();>56</div> <div id=element3 onclick=add();>42</div> <div id=element4 onclick=add();>109</div> <div id=element5
What are the differences between using $(#element).click(function() { alert(test); }); and <div id=element onclick=alert('test');></div>
I wrote function onclick of a element <div class=left_collapsed>Որոնում</div> <div class=container style=display: none;> <ul>
I have the following function to remove a DOM element div, $('#emDiv').on(click, ':button[data-emp-del=true]', function
Parent Div Click Function gets called when Child Div Click is clicked. How to
I have a div and when a user clicks on it using the onclick
am having a menu with five elements all under div's with same class. onclick
I want to stop propagation of this div's onclick event to the document? When
I have a div element, with img element in it. onclick of div i
HTML page: FIRST ELEMENT The onclick function of FIRST ELEMENT (which is < h1

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.