Actually the following problem is jquery code:

$(document).on("ready", function() { $('input[advancedtype="searchselect"]').after('<div class="drophelp">TEST</div>'); } $( '#content' ).load( "form.html"); } //form.html <input type='text' advancedtype='searchselect'> 

Actually the DOM has changed and TEST is not added after loading, how to get around this point? who faced?

Are there any quick fixes?

  • Well podoebazh something ... - Qwertiy ♦

3 answers 3

The bottom line is that the functions applied to the DOM after the upgrade are not valid, since all the elements are updated and the old events to them are erased. One solution is to reload all functions again after each loading "form.html".

How to do it? There is one easy solution: write all the necessary code into a separate function and call it every time. Example:

 function func() { $('.button0').click(function() { alert('НаТалось'); }); }; $(function() { func(); $('.button1').click(function() { $('.but').html('<button class="button0">ОбновлСнная кнопка</button>'); func(); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p class="but"><button class="button0">НаТми Π½Π° мСня</button></p> <button class="button1">ΠžΠ±Π½ΠΎΠ²ΠΈΡ‚ΡŒ</button> 

But in general for events of pressing, guidance, global events can be used, but in your case this is not appropriate. Example:

 $(function() { $(document).on('click', '.button0', function() { alert('НаТалось'); }); $('.button1').click(function() { $('.but').html('<button class="button0">ОбновлСнная кнопка</button>'); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p class="but"><button class="button0">НаТми Π½Π° мСня</button></p> <button class="button1">ΠžΠ±Π½ΠΎΠ²ΠΈΡ‚ΡŒ</button> 

    We check if the content has changed only then we add the item.

     $("body").on('DOMSubtreeModified', "#content", function() { $('input[advancedtype="searchselect"]').after('<div class="drophelp">TEST</div>'); }); 

      On an event, make $().remove() , then $().append() ; The second option is to change the event through $().css('display', none) ;