1252748
1252748

Reputation: 15362

load <options> into <select> when <select> is clicked

Is there no way to populate a <select> list when the <select> element is clicked on?

$(document).ready(function(){
    $("body").on("click", "select", function(){
        ajax(); //should append additional <option>s to select
    });
});

Is there any solution for loading the content of the <select> when it is clicked on?

http://jsfiddle.net/AxEAe/

EDIT:

Tried surrounding <select> with a <div> and attaching click event to that. No luck.

Upvotes: 1

Views: 133

Answers (1)

Zevi Sternlicht
Zevi Sternlicht

Reputation: 5399

$("body").on("click", "select", function(){
        $(this).children('option:last').insertAfter('<option>Another option</option>');
});

Upvotes: 2

Related Questions