powtac
powtac

Reputation: 41070

jQuery: match an element by searching for style="font-size: 70%"?

How can I match all a-tags which have a font-size of 70%?

<a href="/tag/customersproducts" style="font-size: 70%; text-decoration: none;">customersproducts</a> 
<a href="/tag/dealers" style="font-size: 70%; text-decoration: none;">dealers</a> 
<a href="/tag/dealershops" style="font-size: 101%; text-decoration: none;">dealershops</a> 
<a href="/tag/dealersvendors" style="font-size: 120%; text-decoration: none;">dealersvendors</a> 
<a href="/tag/deliverymethods" style="font-size: 70%; text-decoration: none;">deliverymethods</a> 
<a href="/tag/departements" style="font-size: 70%; text-decoration: none;">departements</a> 
<a href="/tag/departments" style="font-size: 104.545%; text-decoration: none;">departments</a> 

This does not work:

$('a[style*=font-size:70%]')

This is the page: http://cakeapp.com/tags/all with installed jQuery for testing...

Upvotes: 0

Views: 535

Answers (2)

Brother Erryn
Brother Erryn

Reputation: 841

The style attribute isn't a string, so that type of selector won't work (in fact, the console in Chrome and Firefox both say "indexOf is not a function" when trying this one).

I don't know how much control you have over this, but have you considered making those sizes a set of classes instead? It looks like you're calculating each size on the fly, so you might have to do some grouping/rounding to make that work. Alternatively, when you're creating those inline styles, could you also attach a class to items at 70% at the same time?

Upvotes: 1

David Hedlund
David Hedlund

Reputation: 129812

What you want is a filter:

$('a').filter(function() { return this.style.fontSize == '70%' })

Upvotes: 5

Related Questions