Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress From Bootstrap to WordPress Setup a Bootstrap Theme Adding Ability for Dropdown Navigation

Gbolade Ogunfowote
Gbolade Ogunfowote
3,812 Points

Why not switch classes with jQuery

I was wondering if it won't be a better idea to search the DOM for sub-menu, and remove it and add "dropdown-menu" instead. This way we don't have to bother with changing or writing CSS, just let it use the default CSS for bootstrap. This could also work with "current-menu-item", switching it to active. I think this would be more elegant, what do you think?

1 Answer

Depending on the situation it could come down to preference, but I believe that the consensus is that it is usually better to toggle classes than change inline-styles with jQuery.

The main reasons you might not toggle classes would be if you are dynamically setting values for certain styles (like color depends on time of day or something) OR if you are using animations with callbacks on complete.