How can i remove elements without id property from the collection (not from the DOM itself) on which the plugin was invoked?
<span id="id737293" class="attach"></span>
<div class="attach"></span>
jQuery invocation and plugin:
$('.attach').attach();
(function($) {
$.fn.attach = function(options) {
// Remove elements (without id) on which the plugin was invoked
var valid = ???;
// Loop each valid element (with id attribute) and process
valid.each(function() {
});
return this; // Maintain chainability
};
})(jQuery);
Use .filter to remove elements without an ID.
http://jsfiddle.net/5Kn9W/2/
or
var valid = this.not(':not([id])');– http://jsfiddle.net/5Kn9W/1/