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

Ruby Build a Simple Ruby on Rails Application Frontend Development Adding Interactivity

JS Hover requires refresh after posting. Any ideas?

In this video, a hovered status is crated via javascript by toggling a 'hover' class upon hover action.

This works fine, but when I post a new status and return to the page, this javascript functionality fails.

Refreshing the page fixes the problem, but it should work without needing a refresh!

Would it be better to create display/display none with css?

Or perhaps you know a JS fix. My JS is in the .coffee file and format as per the video.

Maybe:

.status .admin {
display:none;
}

.status:hover .admin {
display:inline;
}
Andrew Shook
Andrew Shook
31,709 Points

Haven't done this course so I'm making a guess here, but is the status adding via ajax?

2 Answers

If I'm honest - I don't know. There wasn't a mention of Ajax during the course, but I'm not at all savvy with ruby so it might be included in the inner workings?

The CSS gives the desired result, I'm just wondering if there was a reason why the instructor used JavaScript over CSS..

Thanks for your response

Andrew Shook
Andrew Shook
31,709 Points

Yeah I don't know. I would use :hover psuedo class.

My guess is that the new status is loaded via ajax and the hover js they used isn't being applied to it because its load after the page loaded and the Javascript finished running. But works after the page is refreshed because it is being loaded normally.

I guess he used javascript just to show up the coffee part... I did with css...

Also did using sass instead of writing regular css...

Don't know about the ajax tho. it looks like your problem is something else.