Jquery on click event binding and unbinding

emmm, or the code is clearer, I really don"t know how to describe this

 //code,
            $("-sharptagList").on("click","li",function () {
                    $(this).unbind("click").click(function () {
                        var selectedTag = $.trim($(this).text());
                        tmplTagListObj.forEach(function (item, index) {
                            if (item.name == selectedTag) {
                                $("-sharptplContent").insertAtCaret("$" + "{" + item.code + "}");
                            }

                        })
                    })
                // }
            });
       

above is to click on the li tag to perform a text interpolation operation, (insertAtCaret this is a function of interpolation, normal no problem)
the effect is as follows

clicking on the title will automatically generate a placeholder for $(title). The tag column can dynamically add a new tag
. The previous practice is to bind the click event directly. The bug that appears is as follows: the
constraint means that the tag name of the same pop-up box cannot be repeated, and the tag name under different pop-up boxes can be repeated
add a tag to the a pop-up box and cross out the a pop-up box. Dynamically add a tag with the same name in the b pop-up box, click to generate two placeholders, repeat the operation, to c pop-up box is the same three placeholders, and so on

then changed to the description of the problem. Obviously, there is no response on the first click, and all the normal reactions begin with the second click of the mouse.
I want to know
how to solve the situation that the first click does not take effect?
ps: tries to simulate a click event in the outer layer, but it doesn"t work, and then simulates a click event in the inner layer. Console data is printed many times in F12, which doesn"t work.

Mar.30,2021

it's obvious that you didn't clean up the data in tmplTagListObj after you cross out the tag. In fact, after adding the same tag, there is already the same tag in tmplTagListObj

.

and you use forEach in the click event to traverse tmplTagListObj and enter the if statement multiple times and then add multiple placeholders

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-1b3725c-2b7ea.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-1b3725c-2b7ea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?