Reputation: 334
I want to find all elements inside #Grid, then inside a first "TR" tag they should have attribute role="row" and attribute role="columnheader". I've got it and it works fine. Example:
var elements = $("#Grid").find("tr").attr("role","row").first().find("th").attr("role", "columnheader");
What I want to do is to filter it only to elements which meet the condition: offsetWidth < scrollWidth
I tried like below, but this is the incorrect result:
var elements = $("#Grid").find("tr").attr("role", "row").first().find("th").attr("role", "columnheader");
var filtered = elements.filter(function () {
return $(this).offsetWidth < $(this).scrollWidth;
});
I can use this function as well, but I don't really know how to combine it in jQuery:
function isEllipsisActive(e) {
return (e.offsetWidth < e.scrollWidth);
}
Upvotes: 0
Views: 85
Reputation: 4678
Don't use $(this), use the element variable existing in the filter function.
var filtered = elements.toArray().filter(function (e) {
return e.offsetWidth < e.scrollWidth;
});
Upvotes: 1
Reputation: 2756
Should work:
var filtered = elements.filter(function () {
return this.offsetWidth < this.scrollWidth;
});
Upvotes: 1