0

Just curious about which of these would be faster?

$('ul.dropdown a').first().click(function(event) {
    event.stopPropagation();
    return false;
});

or

$('.dropdown > li > a').click(function(event) {           
    event.preventDefault();
});

Is there any difference?

3
  • the second one will be faster.. Commented May 10, 2012 at 13:17
  • 5
    Well, they do two different things... Commented May 10, 2012 at 13:17
  • Moreover, if there's a difference for the machine, I doubt there's one for the human browsing the website. Commented May 10, 2012 at 13:23

2 Answers 2

1

They do two different things.

I guess you're asking about > V.S. space:
> is fatser then space, as it goes one level deep only.

The tip with selectors is make the right side of it more precise than the left.
Read more here

Sign up to request clarification or add additional context in comments.

Comments

0
$('.dropdown').find('a').on('click', function(e) {           
    e.preventDefault();
});

1 Comment

Could you update your answer sharing why that might be fastest?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.