Question: This is my first time here, I hope that this is clear.

So i will have code similar to this this.

```
 <span class="mediaSource ui-draggable" id="purchsePlay7915504">
    <a href="" onclick="return popup_window(this, 'MediaView', 850, 680)" class="control"  enter code hereid="GenericLink"></a>
    <img id="Any_71" alt="Media Source" src="images/9672web.gif" class="mediaStationIcons mediaWin"/>
    <img class="player" alt="Media Source" src="images/playmedia.gif" style="display: none;"/>
    </span>  

```

The href portion is generated on the backend, and I have no access to it.

I need to modify some existing jquery code to do something based on what the 'onclick' function is(there are different ones e.g. popup\_window1,popup\_window2 etc.) .

I tried something like this:

```
$('.segmentLeft span.mediaSource').click(function(){
if ($('span:contains("popup_window")').length > 0) {
 do something
}
});

```

but it does not seem to work.

Answer: 
Try $('span > a[onclick\*="popup\_window"]');
First select the a tag correctly, then in the click look at the attribute's value.

```
$(document).ready(function() {

  $('span.mediaSource a.control').click(function(e) {

    if ($(this).attr('onclick').indexOf('popup_window') {
      //Do Stuff
    }

    e.preventDefault(); //Cancel the click action
  });

});

```

There is no need to use the selector to check the onclick attribute, it will be very slow as the selector engine may need to check multiple elements.