English 中文(简体)
jquery 摘除不从事有活力的iv夫工作的父母
原标题:jquery remove parent not working on dynamically created divs

试图利用 j,使 but子搬走母。

我的发言:

<div class="web_store_fields" id="web_store_input1">
<p>
<label for="web_store_address[]"  >Store Address : </label>        
<input name="web_store_address[]" class="web_store_info"  type="text" value="http://www." size="35"/>
<input class="button_remove_web_store" type="button" value="Remove"  />
</div>

jquery divmov Code:

$( .button_remove_web_store ).click(function() {
$(this).parents("div:first").remove();
});

this works ok for the div that s in the html when the page loads but not for div created dynamically by user (using this jquery code):

$( #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().attr( id ,  web_store_input  + newNum);
$( #web_store_input  + num).after(newElem);
});

简言之,充满活力的创造正在打工,问题在于消除这些 d。

任何建议都会受到高度赞赏。

最佳回答

使用所授予的手稿(on)和选编班子,以便以后加入的任何新纽子仍将有效。

$( body ).on( click ,  .button_remove_web_store , function() {
    $(this).parents("div:first").remove();
});
问题回答

<><0> 使用live 手勒——在“Query 1.7 和 移至“j Query 1.9——这是对许多人的突破性变化。

相反,使用。 手稿目前建议采用的方式:

$(document).on( click ,  .button_remove_web_store , function() {
    $(this).parents("div:first").remove();
});




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签