Kenny Lajara Kenny Lajara - 2 years ago 131
jQuery Question

JQuery selector for domain list

I have a function in my code that I need to modify links in my page, it looks something like this:

// code here related to HREF attr
// Code relate to the TARGET attr

I need to apply this function on all the links and targets of forms pointing to some specific domains. Let's say I have a list like this one:,,

How can I modify the selector in a way it could apply it only to links and form pionting to the domains in the list?

Answer Source

You can use new RegExp() with parameter array list joined with delimiter "|", RegExp.prototype.test()

var list = ["","",""];

$("a, form").each(function(i, el) {
  if (new RegExp(list.join("|")).test(this.href || {
    // do stuff


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download