Is it possible to call the Ready () function again in jQuery

I have this code

   $(".insert").click(function(){
            $(".insert").ajaxStop(function(){
                $(".load").hide();
            });
            $(".insert").ajaxStart(function(){
                $(".load").show();
            });

            $.ajax({
                type: "GET",
                url: "edit.php",
                data: "action=add",
                success: function(msg){

                    $(".control").append(msg);
                }
            });


        });

as you can see, this code adds the edit.php HTML response to .control

problem

after adding html .. all jquery changes will not be applied in it .. because $ (document) .ready () has already been called before, this HTML code was born ...

Can I call $ (document) .ready () while I make any changes?

+3
source share
7 answers

Check out jQuery live . It is designed to automatically bind events for new elements. It works for clicks, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress and keyup.

+6
source

, document.ready, , , . , live(), , DOM live().

, , , :

$(document).ready();
+9

:

        $("div.value").off("click");
        $("img.cancelEdit").off("click");

        $("div.value").on("click", function (e) {
            var $this = $(this);
            $this.hide();
            $this.next().show();
        });

        $("img.cancelEdit").on("click", function (e) {
            var $this = $(this);
            $this.parent().hide();
            $this.parent().prev().show();
        });

Selector.Live();

+2

, ready ( ) jQuery- .

+1

If you need to start when the document is ready, wrap it in $(document).ready(function(){});and it will start at the appropriate time.

You can add rules to the .ready () method documentin several places.

0
source

Use on () instead of live (). live () has some disadvantages and is depreciating.

0
source

Source: https://habr.com/ru/post/1710536/


All Articles