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"]');
`:contains` applies only to text within a specific element. If the text "popup\_window" is not literally spelled out within the node `span`, it's not going to apply.

I also noticed that your `if` check checks the general `span`, instead of the local `span`. The difference is that when you click `span.mediaSource`, the click is going to apply to *any* span that has a `popup_window` element within it. To check the local span, you would want to use `this`, as in `$(this).children('span:contains("x")')`

You need to know some attribute, class or id of the element you want to select in order to select the entire node. Using the name of the function won't work. Also, if the element you want to select is generated dynamically through JS (which it appears to be), you also have to make sure that element is loaded before you send your script off to try to select it, otherwise you may run into issues with asynchronicity.