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

JavaScript

Sam Hayward
Sam Hayward
11,673 Points

Jquery adding inline styles?

Hey ^ ^ I'm working on my own site and trying to use Jquery to make a menu for mobile view appear and disappear. For some reason, jquery adds its own inline styles to the menu like 'display:block' Its really weird, does anyone have a clue why? Please help =) thanks

4 Answers

Jeffrey Smith
PLUS
Jeffrey Smith
Courses Plus Student 15,508 Points

It's being added as inline style because that is one of the most specific types of styling in CSS so it overrides almost anything else.

jQuery will add 'display:block' if you are using the show() method. The show method restores the hidden element back to its initial stateโ€” so if you had an element that was initially set to 'display:inline' and then it was hidden, the show() method would have it display inline again.

http://api.jquery.com/show/

Nicholas Olsen
seal-mask
.a{fill-rule:evenodd;}techdegree
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 Points

I'm not sure how similar it is to the problem you're experiencing but I had a similar problem when I was working on this menu.

jQuery's animate() function adds inline styles to the menu so I had to use the animate function to reset the inline styles back to what I wanted them to be.

As Josh said, if you have code please post it.

Do you have any code samples?

Sam Hayward
Sam Hayward
11,673 Points

Sorry for the late reply i've been really busy! It was really simple just using .show() and .hide() on a div. Now i realise i wanted .toggle() Just happy that it's something that's supposed to happen Thanks guys =)