jQuery filter and find combined in order -


hy, ve got set (var content) of 2 elements: firstly img-element , secondly p tag contains many elements (img-tags well).

now want img-elements within set , subelements.

i've got content.filter('img').add(content.find('img')). 

but want items in order appear within set or html-document.

therefore wrote function:

jquery.fn.extend({     filterandfind: function(selector) {         selector = selector.tolowercase();         var els = $([]);         this.each(function() {             if(this.nodename.tolowercase() == selector) {                 els = els.add($(this).clone());             }             els = els.add(selector, $(this));         });         return els;     } }); 

but when a

content.filterandfind('img').wrap('<div class="slides_page"/>') 

they appear not in right order.

does know how tackle this.


Comments