This can be much simplified by using
The upsides of this, besides being more concise, are that it the reader of your code can see which parent you're accessing without having to count the calls to
This...is pretty bad. But there's no real way to tell how bad it has to be given other constraints. For instance, if this is a JS file meant to affect a page whose HTML you don't have control over, then you can't do much better than something like
If this is an element you have to access a lot, consider adding an id or class to it, then selecting by that.
Again, if you don't have access to the HTML, you'll need to add it yourself at runtime
Consider pasting some surrounding code for more insight.
Besides what sepp2k said:
Instead of accessing the DOM object of the first child and then rewrapping it in a jQuery object, you can use the method
So instead of this:
And there are possibly more ways to optimize it, if you show the HTML it's operating on.
1. Instead of doing so many
2. You can use
This is better:
Though jQuery has a
Assuming you don't have access to the html (where you could assign an id the child), the only real option you have is:
if you are going to be accessing the element more than once you could assign it on load:
knowing more about why you need to do dom traversing, may yield further advice.