Binding the click event to the element of the initial visibility:hidden in jquery does not take effect?

starts with a ul list visibility:hidden , use jquery to bind the click event to the li, click a button to display it, and then click li to trigger the bound click event.

then remove the initial visibility:hidden , and the bound event is fine.

is there any solution, or is there something wrong with my writing?

<div class="div-search-helper">
    <input class="scene-search-input js-search-select1" type="text" style="margin-left:10px;" placeholder="," />
    <ul class="ul-helper-search js-ul-helper">
        <li>11</li>
        <li>1</li>
        <li>2</li>
        <li>2</li>
        <li></li>
        <li>0</li>
        <li>0</li>
        <li>0</li>
    </ul>
</div>

$(".js-search-select1").focusin(function(){
        $(".js-ul-helper").css("visibility","visible")

        $(".js-ul-helper").on("click","li",function(){
            console.log("asdasdasd")
            $(".js-search-select1").val($(this).text())
        })
    })

    $(".div-search-helper").on("click","li",function(){
        console.log($(this).text())
        $(".js-search-select1").val($(this).text())
    })
$(".js-search-select1").focusout(function(){
    $(".js-ul-helper").css("visibility","hidden")
})


.div-search-helper {
    display: inline-block;
    position: relative;
}
.ul-helper-search {
    position: absolute;
    left: 10px;
    width: 270px;
    border: 1px solid -sharpeeeeee;
    border-top: none;
    background: -sharpFFF;
    height: 200px;
    overflow-y: auto;
    z-index: 1;
    visibility: hidden;
}
.ul-helper-search::-webkit-scrollbar {display:none}
.ul-helper-search li {
    padding: 2px 5px;
}
.ul-helper-search li:hover {
    cursor: pointer;
    background: rgba(220, 220, 220,0.5);
}
.ul-helper-search li+li {
    border-top: 1px solid rgba(220, 220, 220,0.5);
}
Mar.14,2021

you should just use an agent.

by the way, where is your way of writing?

< hr >
  1. bind events uniformly with .on ()
  2. in fact, I recommend that you use an agent and write it as:

    
    

     $('.js-search-select1').focusin(function(){
        // $('.js-ul-helper').css('visibility','visible')
        $('.js-ul-helper').show()
    
        $('.div-search-helper').on('click','li',function(){
            console.log('asdasdasd')
            $('.js-search-select1').val($(this).text())
        })
    })
    
    $('.js-search-select1').focusout(function(){
        $('.js-ul-helper').hide(500)
        // $('.js-ul-helper').css('visibility','hidden')
    })
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b386b6-2c0f4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b386b6-2c0f4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?