Pavel Straka Pavel Straka - 1 year ago 131
jQuery Question

JQuery UI autocomplete - one click show, second click hide

I have this autocomplete:

$('#plemena_select').click(function() {
$('#col4_filter').autocomplete("search", "");

I would like to have a link. If the autocomplete is not visible, the click on the link would show it. And if the autocomplete is visible, the click would how it. (One click show, second click hide).
How could I do that?
Thanks everyone.

Answer Source

i'm not familiar with JQ autocomplete, if you want toggle functions between clicks you can use this:

function hideDiv () {
    //do somthing
    $('.btn').one('click', showDiv);

function showDiv () {
    //do somthing
    $('.btn').one('click', hideDiv);

$('.btn').one('click', hideDiv);

Or you can use even odd method:

var i = 0;

$('.btn').on('click', function () {

    i += 1;
    var tog = function (someNum) {
        return ((someNum % 2) === 1) ? true : false;
    return ( tog(i) ) ? console.log('on') : console.log('off');


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download