Add item AFTER download

I have this code

$(".test_init").click( function(){ var win = $(this).next(".test_wrap").find(".test_drop"); if ($(win).html().length) $(win).empty().hide("fast"); else { $(win).load("URL"); } }); 

Which returns me some html form without a close button

I want to add a close button using this method without adding it to every single function

 $('*[class*="_drop"]').change(function() { $(this).append($('<a />', { class: 'close-drop', click: function(e) { e.preventDefault(); alert("test"); }}) ); }); 

But nothing happens - I do not understand why the close button does not add

 <div class="test_wrap relative"> <div class="test_drop absolute"></div> </div> 

Example: http://jsfiddle.net/fppfyey7/10/

0
javascript jquery
Nov 23 '15 at 16:13
source share
2 answers

My solution (not good enough, still working)

 $('*[class*="_drop"]').ajaxStop(function() { $(this).prepend('<a onclick="$(this).parent().empty().hide(\'fast\');" class="close-drop"></a>'); }); 

If this is the best solution, mark it as an answer!

0
Nov 24 '15 at 11:59
source share

Your problem is with your CSS, not your JS. A button is added, but you do it with your style.

For example, in this script, I add a button with your JS code and your CSS:

Fiddle 1

Now, in this, I will simply remove the absolute and relative classes:

Fiddle 2

0
Nov 24 '15 at 9:36
source share



All Articles