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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:02:42+00:00 2026-05-26T18:02:42+00:00

I’m building a custom autocomplete for a search box on our site. I’ve coded

  • 0

I’m building a custom autocomplete for a search box on our site.

I’ve coded a keyup event handler to handle keyboard input for scrolling through the autocomplete list, having enter select elements/submit form, etc…

The problem I am having is I want an enter keypress to act as a the equivalent of a click on the element. However when the enter keypress calls the click method bound to the <p> tag, in Chrome, the click event handler can’t be found. In Firefox it works just fine.

Am I not allowed to bind click event listeners to <p> tags in Chrome? What’s going on? This works perfectly in Firefox.

Here is relevant code for the concrete examples:

I’ve bound the click event via jQuery’s live method to all list elements that are appended to my list during the autocomplete like so:

$('.suggestion .section li p').live( 'click',  function (){ 
        
        debugLog("a p tag was clicked");
        
        $("#search-input").data('skip-hide', true);
        $("#search .suggestion").data('selected-index', -1) ;
        
        $("#search-input").val($(this).parent().data('search-text'));
        $("#search-input").closest("form").submit();

    });

Then a bit later I do this:

$("#search-input").keyup(function(event){
    
    switch(event.keyCode )
    {
        case 13:
        if($("#search .suggestion").data('selected-index') != undefined){
            debugLog('a defined index was set when enter was pressed');

//THIS IS THE FAILING LINE IN CHROME
            $("#search .suggestion li p")[$("#search .suggestion").data('selected-index')].click();
            return false;
        }

The html snippet that my autocompete fills out looks like this:

<form id="search-form" action="<?php echo $this->baseUrl(); ?>/search" method="get" accept-charset="utf-8">
            <div id="search">
                <input id="search-input" type="text" class="input-box input-focus" name="q" value="Enter a product or store..." /><input type="image" id="search-form-image" src="/images/nav-btn-search.gif" />
                
                <div class="suggestion" style="display:none;">
                    <div class="section" id="stores-autocomplete">
                        <strong>Stores</strong> 
                        <ul>
                        </ul>  
                    </div>
                    <div class="section" id="searches-autocomplete">
                        <strong>Searches</strong>
                        <ul>
                        
                        </ul>
                    </div>
                    <div class="section lastChild" id="coupons-autocomplete">
                        <strong>Coupons</strong>
                        <ul>
                           
                        </ul>  
                    </div>
                </div>
            </div>
        </form>
  • 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-26T18:02:43+00:00Added an answer on May 26, 2026 at 6:02 pm

    Use .eq() instead of [] to select the paragraph. Then, invoke .click() (as a jQuery method):

    $("#search .suggestion li p").eq($("#search .suggestion").data('selected-index')).click()
    

    When using square braces, you’re selecting a DOM element, and trying to invoke the DOM .click method. The solution involves using .eq(), so that a jQuery object is selected, so that jQuery’s .click(), aka .trigger('click'), method can be invoked.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am using Paperclip to handle profile photo uploads in my app. They upload
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.