jQuery issue - $(this).parent().remove(); -



jQuery issue - $(this).parent().remove(); -

this question has reply here:

events triggered dynamically generated element not captured event handler 5 answers

i found solution many problems before here still cant find reply on problem. have container , adding elements within dynamically jquery. within added div's have button want when click button , button removed. here tried far no success.

html

<div id="menucontainer"> <ul id="menu"> <li><a href="#" id="addcolumn">add element (max 5)</a></li> <li><a href="#" id="addcard">---</a></li> <li><a href="#" id="delcolumn">---</a></li> <li><a href="#" id="delcard">---</a></li> <li><a href="#" id="tblreset">---</a></li> </ul> </div> <div id="columns" style="width: 1000px;"></div>

jquery:

$(function() { var columns = $('.column').size(); $('a#addcolumn').click(function() { if (columns < 5) { var columnname = prompt('Внесете назив за колоната: '); var temp = columns + 1; $('<div class="column">' + columnname + '<button id="' + temp + '" style="float:right;" class="btnremovecolumn">x</button></div>').appendto('div#columns'); columns++; } else { alert("Имате максимален број на колони во таблата"); } }); $(".btnremovecolumn").click(function(){ $(this).parent().remove(); }); });

all css can tried on external site fiddle see how (not) working. link here

$(document).on("click", ".btnremovecolumn", function() {

for dynamic elements, events should delegated.

jquery

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -