Loop through elements in has selector

Loop through elements in has selector

I have the below code. Right now it only gives me the first element that satisfies the has condition. How can I loop through all the items returned/satisfied from has selector and perform the color change function. 

       var data = $('.tab-pane').has('.input-validation-error').attr('id');
            var href1 = "#" +data;
            $("a[href=" + href1 + "]").css("color", "red");


Thanks