1

I have a question for the jQuery experts. I am trying to set a margin-left on a sliding div in a slider im making.

Is it faster for DOM Traversal and CSS rendering to do:

Insert inline css via .css('margin-left','-690px');

OR

Create a new css Class and insert it .addClass('marginLeftClass');

Does one have a potential advantage over another?

1 Answer 1

2

Adding the styles via .addClass is faster as the styles are already loaded.

By using .CSS() in jQuery you are injecting the values and making the element adapt to new CSS on the fly.

Its probably easier to think about it in larger terms, would you rather inject 10 seperate css properties on the fly via jQuery CSS properties, or just simply toggle a class? It's easier to add the class, and MUCH easier to manage.

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.