Why does jQuery's remove() method accept a selector? -
i noticed strange thing when using remove
jquery. although jquery cleary states that:
selector
type: string
selector expression filters set of matched elements removed.
if try code:
$element.remove('.k-grouping-header,.k-group-cell,.k-group-col,.k-grouping-row');
it won't work expected , have use
$element.find('.k-grouping-header,.k-group-cell,.k-group-col,.k-grouping-row').remove();
did guys noticed or me doing wrong? jsfiddle: http://jsfiddle.net/yzfrt/
remove()
take elements selected out of dom, whether pass argument or not.
passing argument (selection) remove()
filter elements match selection.
presumably in first instance, have parent selected. remove()
try remove element, since (probably) doesn't match .k-grouping-header,.k-group-cell,.k-group-col,.k-grouping-row
stay is.
your confusion comes not understanding difference between filtering , finding
your second attempt correct.
why allow selector @ all?
chaining. consider have many elements selected call jquery method on, maybe you'd change colour:
$('div').css({color:"#f00"})
but wanted remove ones class .remove
? can still chain, , filter ones remove:
$('div').css({color:"#f00"}).remove('.remove')
which, way, same as:
$('div').css({color:"#f00"}).filter('.remove').remove()
Comments
Post a Comment