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

is this possible to use toggle here ?

$(".intro_image a").click(function(){
   $("#welcome").toggle();
   $("#intro").css("top","120px");//here i want to use toggle
});

Hi Ashish,

Do you mean that you want to apply and remove that css each time the anchor tag is clicked?

3 Answers

In that case, I recommend that you add a class rule to your css that contains all the styles you want to toggle and then use the toggleClass() method on that element. http://api.jquery.com/toggleClass/

.class-name {
  top: 120px;
  /* whatever else you need */
}

jQuery -

$("#intro").toggleClass("class-name");

Basically, adding and removing the class will have the effect of adding and removing the styles.

Replace class-name with whatever class name you want to use.

Let me know if I've misunderstood what you're trying to do.

Also, keep in mind that top will be ignored if you don't set position to something other than static. e.g. absolute, relative, or fixed.

Do you have this in your #intro styling?

Hi Ashish,

Yes it should be possible, but I believe from the code you have written that the welcome id element will be toggled. Please see the following documentation on toggle: http://www.w3schools.com/jquery/eff_toggle.asp and the example put in practice: http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_eff_toggle

Thank you, Adrian

Jason Anello , yes i want to do same