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
Frank Cameron-Wilson
8,814 Pointsadding a css property
Hi, I'm trying to add a css property once a link is clicked, but with no success. Can anyone point me in the right direction, please.
$(document).ready(function(){
$('nav a').click(function(){
$(".text_box").css("-webkit-animation":"sliderIn 5s linear");
});
});
The .text_box is a div, and i have already written the keyframe rule. Thank you
4 Answers
Sean T. Unwin
28,690 PointsYou need to add curly braces around the strings within the css function like so:
// within the click function
// line-break added for clarity
$(".text_box").css(
{ "-webkit-animation":"sliderIn 5s linear" }
);
Kevin Korte
28,149 Points...
Sean T. Unwin
28,690 PointsYou can add animation using the css function - http://jsfiddle.net/JVdkv/
James Barnett
39,199 PointsSean T. Unwin - I'm always down for a good demo, they're great for clearing things right up.
Sean T. Unwin
28,690 PointsJames Barnett. I concur! :) Note: For anyone viewing the fiddle without a webkit browser you will need to edit the browser prefix in the css and js sections.
Sean T. Unwin
28,690 Pointstried to edit reply to Kevin...
Kevin Korte
28,149 PointsYeah, I realized that after I wrote me response. I learned something new today.
Frank Cameron-Wilson
8,814 PointsThank you all, glad to have created a buzz around the subject.. ;-) Haven't seen jsfiddle before, top site.
James Barnett
39,199 PointsPersonally I find codepen to have a far superior user experience over jsfiddle.
James Barnett
39,199 PointsJames Barnett
39,199 PointsFrank Cameron-Wilson -
Alternatively, instead of adding curly braces you can swap out the colon for a comma in the CSS string.
However, you can't mix and match the 2 syntaxes