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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:04:15+00:00 2026-05-16T11:04:15+00:00

I´m using an unordered list to replace the select function. I have a state

  • 0

I´m using an unordered list to replace the select function. I have a state and city combo where I choose the state and then it auto complete the city. A traditional select for registration.

The problem is that I´m able to do the jSon stuff, but when I load the < li > into the cities I´m not able to get the click. I will show the code:

$('ul#states li a').click(function() {

    var uf = $(this).find('span.value').html();

    var $comboCidades = $('ul#cities');
    if (uf == 0) {
        //$comboCidades.html('<a href="javascript:;"><span>Selecione</span></a>');
        return;
    }
    $.getJSON('/contato/cidades/', { uf: uf }, function(data) {
        var options = ''; 
        var dataLength = data.length;
        for (i = 0; i < dataLength; i++) {
            options += '<li><a href="javascript:void(0);">'+data[i]['nome']+'<span class="value" style="display:none">'+data[i]['id']+'</span></a></li>';
        }   
        $comboCidades.html(options);
    });         

});

That´s the Jquery code, I request /contato/cidades/ that Return´s to me a enconded json with all the cities, it works perfect.

So, I populate a < ul > tag with the command $comboCidades.html(options); and IT WORKS, I can have the < ul > with all the cities separated by < li >, the problem is, that I´m not able to select the cities < li >, it did not get the values, but, if I add a < li > without being loaded by json, it can get the value from the li.

Is there any problem loading < li > with jquery and html() that it´s not a real < li >? Can I fix it with some kind of jQuery functions?!

MY HTML CODE:

<div class="input">
    <label>Cidade:</label>
    <div class="select">
        <p><a href="javascript:;"><span>Selecione</span></a></p>
        <ul>
            <li><a href="javascript:;">Santa Catarina</a></li>
        </ul>
    </div>
</div>
  • 1 1 Answer
  • 5 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-16T11:04:16+00:00Added an answer on May 16, 2026 at 11:04 am

    I assume you’re assigning the click event for the elements under #cities when the page loads.

    Problem is that if those elements don’t exist when page loads, they don’t get the event.

    Try using .live() instead:

    $('ul#cities li a').live('click', function() {...
    

    Or better, use .delegate() if you have jQuery 1.4 or later.

    $('ul#cities').delegate('li a', 'click', function() {...
    

    This places the handler on ul#cities so as long as it exists when the page loads, the handler will be there for you. (Similar to live() which places the handler higher up the DOM.)

    Side note, when you’re referencing an ID, $('#cities') is a little better than $('ul#cities').

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

Sidebar

Related Questions

I want to create a form using an unordered list ul must have only
I have an unordered list, and am using jquery to find the last ul
I am using an unordered list where the actual list items have a rounded
I currently have a drop-line horizontal menu using an unordered list with the following
I have an unordered list I'm using for a menu. Each item has a
I have an unordered list that is being loaded from an external file using
I have items contained in an unordered list. I have hidden divs (using display:none;)
been experimenting with unordered list UL and i have seem varios examples of using
I have the following unordered list that is rendered as a menu. Using jQuery,
Is it possible using a standard unordered list with a fixed height, to have

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.