jQuery matches the document link and adds class's methods

  • 2020-06-22 23:49:24
  • OfStack

This article illustrated how jQuery matches document links and adds class. Share to everybody for everybody reference. The details are as follows:

Here jQuery is used to automatically find links to documents and add class, such as doc, xls, pdf documents.


$('a[href]').each(function() {
  if((C = $(this).attr('href').match(/[.](doc|xls|pdf)$/))) {
    $(this).addClass(C[1]);
  }
});

I hope this article has been helpful for your jQuery programming.


Related articles: