在下面的例子中
我想从“父”类中删除“子”类。我试过了
.remove($('parent').children('child'))
</p>
但它不起作用
在下面的例子中
我想从“父”类中删除“子”类。我试过了
.remove($('parent').children('child'))
</p>
但它不起作用
You need periods to get elements by class, for one. For two, that syntax isn't correct.
$('.parent .child').remove();
Do you want to remove the childs (with a class "child") of parents (with a class "parent")?
$('.parent').children('.child').remove();
Or simply:
$('.parent .child').remove();
这会成功的。
$('.parent .child').remove();
(minitech 打败了我 :) )
many ways: if you have no identifier for the child then you can remove child my its position on the parent :
var p ='.parrent';//identify the parrent
$('p').children('1').remove();//remove the child placed in ('1');
remove Directly [ if you have a identifier ]
$('.parent .child').remove();//it removes child from the parent.
if you dont know what the parent is.
var selector = '.child';//you must identify ONE child to find its parent
var sP = $(selector).parent();//selecting the parent for this Child
//now removing the Child [identifier = position of child]
$(select).parent().children("5").remove();
In case if you have too many child with same class then but the parent is different for all. you can remove the Child also by putting the child class
//[._iNote] is the selector for the removing Element Here.
$(select).parent().children("._iNote").remove();
This script only remove selected child in the the selected parrent . if there is many child with same identifier then They all will be removed so [???] in this kind of case you can create custome attr for selecting the element [only for HTML5 ]. example
<p data-me="someThing-i-like"> [its a custom attr (data-me="someThing-i-like")] </p>
in this case For removing this element,
$("[data-me=someThing-i-like]").remove();// will work fine
if you have any quistion about this post plz plz plz let me know [ comment ]