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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:57:31+00:00 2026-06-11T11:57:31+00:00

Hi, I want to trigger an event on an element list. The list may

  • 0

Hi,

I want to trigger an event on an element list. The list may have multiple selection. The event should be triggered directly, if user clicks on element without ctrl key.
If the user presses ctrl+click then, event should be triggered once the selection is done.
I have written my own logic for that here.
I can prevent event from triggering immediately after click with combination of ctrl. But I am not getting the idea when to trigger my own function(lets say alert here…) ,if there is multiple selection.

  • 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-11T11:57:32+00:00Added an answer on June 11, 2026 at 11:57 am
    var str = "";
    $(document).ready(function() {
    
        // bind only click event
    
        $('ul > li').on('click', function(event) {
    
            // if ctrl key is press
    
            if (event.ctrlKey) {
                str = str + $(this).text() + ",";
            } else {
                str = $(this).text();
                alert(str);
                str = '';  // after alert reset the str
            }
        });
    
        // bind a keyup event
        $(document).on('keyup', function(event) {
    
            // str is not empty and ctrl key is released
            // show alert
            if(str && !event.ctrlKey) {
                alert(str);
            } 
            str = ''; // after alert reset the str
        });
    });​
    

    DEMO

    Note

    you don’t need to maintain any flag for ctrl key press. event.ctrlKey will do this for you.

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

Sidebar

Related Questions

I have a input field. When the onchange event is triggered, I want to
I want to trigger an event when a specific element appears on a page
I want to trigger the submit event of the form the current element is
I want to trigger a hover event for an element using jQuery, but I
I want to trigger an event with a button that changes the visibility of
Is it possible to trigger copy event from JavaScript/jQuery? I want to simulate copy
I have an click function that I want to trigger outside of the function
I have a list of divs that I want to be able to sort.
I've a HTML div and I want to hide it whenever the user clicks
Between keypress/keydown/trigger/event, i'm not sure which is the best for what i want 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.