user4072347
user4072347

Reputation:

Get value from element only if a tag contains a string

<span id="restmap9" class="taLnk hvrIE6" onclick="...">Map</span>1

I want to get the onclick value from this type on code but only if the id contains restmap.

I tried with this code:

if($(v).find('span.taLnk:contains("restmap")').length)2

But it doesn't work.

  1. I can't change this code and can't use the classes as they are used in another part of the website.

  2. $(v) is my source code.

Upvotes: 0

Views: 49

Answers (2)

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382150

For this kind of search over a set of elements with a precise non standard condition, you may use filter :

if ($('.taLnk',v).filter(function(){
    return /^restmap\d+$/.test(this.id)
}).length) {

Upvotes: 1

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

Simply do like this:

if($(v).find('[id~="restmap"].taLnk').length)

Upvotes: 3

Related Questions