filter() is one of the jQuery DOM traversal methods which constructs a new jQuery object from a subset of the matching elements. The following code is to select all the links in the page whose host name is different than the site host name and then applies css class name “external” $('a')
.filter((i, a) =>
a.hostname && a.hostname !== location.hostname
)
.addClass('external');