html - jquery remove parent not working on dynamically created divs -


A mouse is trying to use jquery to remove its parent div.

My markup:

  & lt; Div class = "web_store_fields" id = "web_store_input1" & gt; & Lt; P & gt; & Lt; Label = "web_store_address []" & gt; Store address: & lt; / Label & gt; & Lt; Input name = "web_store_address []" class = "web_store_info" type = "text" value = "http: // www." Size = "35" /> & Lt; Input class = "button_remove_web_store" type = "button" value = "remove" /> & Lt; / Div & gt;  

jquery div Removal code:

  $ ('.button_remove_web_store'). Click (function () {$ (this) .parents ("div: first"). Remove ();});  

This works fine for that div that happens in html when the page loads, but the user is dynamically created for the device (using this jquery code Click on ():

  $ ('# button_add_web_store') click (function () {var num = $ ('. Web_store_fields'). Length; var newNum = new number (num + 1) ; Var newElem = $ ('# web_store_input' + num) .clone () .ttry ('id', 'web_store_input' + new name); $ ('# web_store_input' + number) .after (newElem);});  

Just to be clear, dynamic construction is working fine, the problem is removing those divs.

Any suggestions will be highly appreciated

Use an accredited handler (with) so that any new buttons added later will still work.

  $ ('body'). ('Click', '.button_remove_web_store', function () {$ (this) .parents ("div: first"). Remove ();});  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -