I'm just wondering if there is a better way to write the following code? Note: below works 100% Fine.
Currently this creates an array of objects. Well I call them objects. I could be better said DOM References. Note: please correct me - eager to learn.
Then it loops through them, hiding all and only showing those that have a class '.contactsBodyMainDisplayMemberUserNameH2' (which is many children down) that matches the text/string in 'sortText'.
var contactsMemberArray = $('#contactsMainWrapperDIV').children()
.map(function() {return $(this);}).get();
$.each(contactsMemberArray, function() {
$(this).hide();
var username = $('.contactsBodyMainDisplayMemberUserNameH2', this).text();
if(username != '' && username.toLowerCase().indexOf(sortText.toLowerCase()) >= 0) {
$(this).show();
}
});
- Is there a quicker way to do this?
- Do I need to map the objects first or can I just sort through them?