Reputation: 14671
With jQuery, how can I find all locations where a specific padding-top value is applied and then increase it from its existing value?
I looked at selectors and I could not find such a thing.
Upvotes: 3
Views: 2147
Reputation: 26228
Do you really mean to search the whole DOM? It's quite inefficient:
$('*').each(function() {
var padTop = $(this).css('padding-top'); // get the padding
if (padTop > 0)
$(this).css('padding-top', padTop + x); // add x to it if more than 0
});
It seems like each()
is better than filter()
because we can filter by padding and increase it in the same scope. It's strongly adviseable to replace '*'
with the most specific selector you can afford to use.
Upvotes: 2
Reputation: 1832
Are you trying to apply this only to a particular type of element (ex: div
s only?). In that case you could do something like @Jeroen mentioned:
$('div').filter(function() { return this.style.paddingTop == "2px"; }) // use your specific padding value.
Upvotes: 1