2275 posts
  • Became a Top 20 Author of the Month
  • Had an item that became a weekly top seller
  • Created a helpful tool/app using the Envato API
  • Created a helpful tool/app for Envato Market users
+15 more
revaxarts
says
or replace
jQuery('#portfolioItem').find('li')
with this
jQuery('li', '#portfolioItem')

Should be fast too because the tag selector is also nativ

1383 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
wpCanyonThemes
says

or replace
jQuery('#portfolioItem').find('li')
with this
jQuery('li', '#portfolioItem')
Should be fast too because the tag selector is also nativ

Aren’t you maybe targeting all list items and the element with the id of portfolioItem. :)

To avoid the find use

$('#portfolioItem li')
470 posts
  • Had an item that was trending
  • Had an item that became a weekly top seller
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 5 years
+8 more
SaurabhSharma
says

In those cases, you’re better of checking the position of an entry and assigning an appropriate class through server side code, PHP in this case, I’m assuming. Then you can merely use the class selector to manipulate specific elements in the front end, as needed.

+1. I always use an algorithm in php to detect nth element for my portfolio pages. This makes sure that the page still looks fine with non-availability of javascript. But it gets into trouble when implementing with sortable portfolio.

1628 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Made it to the Authors' Hall of Fame
  • Has been part of the Envato Community for over 6 years
  • Has sold $500,000+ on Envato Market
+8 more
fuelthemes
says

Love this tool: http://css-tricks.com/examples/nth-child-tester/

Great tool. Only (3n) is needed

2275 posts
  • Became a Top 20 Author of the Month
  • Had an item that became a weekly top seller
  • Created a helpful tool/app using the Envato API
  • Created a helpful tool/app for Envato Market users
+15 more
revaxarts
says

Aren’t you maybe targeting all list items and the element with the id of portfolioItem. :)

To avoid the find use

$('#portfolioItem li')

No, I’m targeting al list items within the portfolioItem

jQuery('li', '#portfolioItem') != jQuery('li, #portfolioItem')

Furthermore jQuery don’t has to check the whole DOM . It just start with the #portfolioItem

614 posts
  • Member of the Envato Team
  • Taught a course or tutorial on Tuts+
  • Had an item that became a weekly top seller
  • Had an item featured in an Envato Bundle
+11 more
Siddharth
Envato team
says

To avoid the find use
$('#portfolioItem li')

No, Xaver’s method is much better.

His code will find the element with the ID and then filter for the tag. Since both use native JavaScript methods, it’ll be blazingly fast.

Your method, while quite adequate for general use, is inefficient. Sizzle, jQuery’s selector engine, handles selectors right to left so there’s a lot of overhead involved. It finds all li elements and then sees whether the ID is a parent.

Mostly, you don’t have to worry about these issues since performance becomes an issue only if you have too many elements.

3535 posts
  • Power Elite Author: Sold more than $1M on Envato Market
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
  • Had an item that was trending
  • Located in United States
+13 more
sevenspark
Moderator
says

For anyone who is interested in/confused about these types of efficiency questions, this quick article from Jeffrey Way is a useful read: Quick Tip: Think Right-to-Left with jQuery

by
by
by
by
by
by