Ron van der Heijden
Ron van der Heijden

Reputation: 15080

What is faster? jQuery css(), jQuery addclass() or just css

Ok in this case I ONLY focus on speed.

What is faster?

  1. $('#header').css({'background':'#ff0000','width':'100px','height':'100px'});
  2. $('#header').addClass('header');
  3. Just use #header in css

I can't get the answer by using FireBug.

Upvotes: 0

Views: 116

Answers (1)

Alfred
Alfred

Reputation: 21406

Just use Embedded CSS, that is #header in css on our page. If you try to apply CSS using JavaScript, your page may not display correctly if JavaScript on browser is disabled. You may use external CSS file, embedded css on head and the inline CSS.

Always give priority to pure HTML and CSS. Trust me, its faster.

Upvotes: 4

Related Questions