0

I'm trying to implement caching and reduced DOM manipulation into my very complex JS code. I just want to make sure, what's more efficient?

1)

var $thebox = $(".textbox[data-title*='"+dt+"']");

    $thebox.remove();

or

2) $(".textbox[data-title*='"+dt+"']").remove(); ?

3
  • 1
    jsperf.com is a great tool to find out the performance of js snippets. Commented Feb 16, 2013 at 13:38
  • Also, there's the profiler built in to Chrome, and now maybe other browsers. Commented Feb 16, 2013 at 13:41
  • $(".textbox.something']").remove(); the most efficient. Searching by attributes is not the fastest. Commented Feb 16, 2013 at 13:42

1 Answer 1

1

They are the same if you use $(".textbox[data-title*='"+dt+"']") one time.

It up to your case. If you have to re-new 'selector' before remove all of them.

You have to use $(".textbox[data-title*='"+dt+"']").remove();

Because $thebox is old now.

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

Comments

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.