views:

87

answers:

1

I am importing a feed into Tumblr and because of the formatting of the site, it shows too many pictures. So to fix that, I thought I would use jquery to remove extra elements.

It turns out that the imported feed uses tables. No worries, I made a jquery call that seemed to work fine on an individual post.

(Pardon the ugly match)

$('.copy div table tbody tr td div table tbody tr td:gt(3)').remove();

This works swimmingly on http://apt.jauderho.com/post/127696762/aaman-lamba-hibiscus

However, going to a page with more than one post, it looks like the second post is being treated as part of the first and hence all the pictures are removed due to the gt(3). My understanding was that using the fragment above, I would be able to iterate on each post leaving only 4 images max per post. See http://apt.jauderho.com/

Can anyone tell me what I'm missing? Thanks.

+1  A: 

Try this:

$('.copy div table tbody tr td div table tbody tr').find('td:gt(3)').remove();

The difference from the original is that the find() is executed for every tr that is matched by the first selector. It will remove every td after the 4th td in every matched tr.

molf
Excellent. That worked as expected. Learned something new today =)
Jauder Ho
Good catch, molf, I don't know why I thought of looping.
Paolo Bergantino