jquery - Adding elements after DOM Ready and make them visible without the need of an event handler -


Adding an element without the need of an event handler after the dond:

  JQuery Document) .ready (function () {var $ body = $ ('body'); var strLoading = '& lt; div id = "ajax_loader" style = "display: none" & gt; loading .. . & Lt; / div & gt; '$ body.append (strLoading); // var $ Loading = $ (' # ajax_loader '); $ (' some unrelated element that is already available at the time the domain is ready) Loading in.) (Function {$ Loading.toggle (); // Load Show Loading Message Through some content In the AJAX $ Loading.toggle (); // loading Message Hide}};});   

Now I would like to show and hide this on demand:

  $ ('some unrelated elements are already available at the time of domain preparation'). Click (Load {$ Loading.toggle (); // Show loading message AJAX $ Loading.toggle (); // Hide loading message via some content});   

It seems that the element is not available in the dom. How can I add it and it can be seen later?

UPDATE: I do not know why it is not working at the end of me, I have just made this Bella and it works fine.

There is nothing wrong with the code you posted elsewhere Try to find the problem.

What are the problems with which element? Why do you think the element is not available? Have you tried $ ()? Length or something similar? If the toggle does not have any effect, then this may be due to additional JS or CSS that you have not shared with us.

Comments