tags:

views:

26

answers:

3

For example, I want to match all links that have the iframe param. Thus, it would match:

<a href="http://www.example.com?iframe"&gt;
<a href="http://www.example.com?iframe=1"&gt;
<a href="http://www.example.com?iframe&amp;sortby=awesomeness"&gt;
+6  A: 

You could use an attribute-contains selector, like this:

$("a[href*='?iframe'], a[href*='&iframe']")

This would also find things like this:

<a href="http://www.example.com?sortby=awesomeness&amp;iframe"&gt;
Nick Craver
+1  A: 

if you use jQuery it would be

var iframeLinks = $("a[href*='iframe']")
EC182
Keep in mind this would also find it *anywhere* in the link, e.g. `www.iframe.com` would also match :)
Nick Craver
A: 

if the search is very specific, you can create a new selector:

(function($) {

  $.fn.tagName = function() {
    return this.get(0).tagName.toLowerCase();
  }

  $.expr[':'].inHRef = function(obj, index, meta, stack){

    if ($(obj).tagName() != 'a')
      return false;

    var afi = $(obj).attr('href').split('?'), sfi, txt = meta[3];

    if (afi.length == 1)
       return false;

    sfi = afi[1];

    // Regular Expression

    var rgCI = '\\'+sfi+'\\gi';

    // case-insensitive
    return (rgCI.match(txt));

    var rgCS = '\\'+sfi+'\\g';

    // case-sensitive
    //return (rgCS.match(txt));

    // IndexOf

    // case-insensitive
    //return ( sfi.toLowerCase().indexOf(txt.toLowerCase()) > -1);

    // case-sensitive
    //return ( sfi.indexOf(txt) > -1);

};

})(jQuery);

$(function() {

    $('a:inHRef(iframe)').css('background-color', '#aaaaa0');

});​

example

example update

example end update

andres descalzo
This would also have the same contains issues :) http://jsfiddle.net/nick_craver/qzpbd/3/
Nick Craver
if, just what was being updated http://jsfiddle.net/qzpbd/4/
andres descalzo