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

How to hide and show part of the page in Ruby with JQuery?

I'm trying to hide part of paragraph of the static page using JQuery in Ruby on Rails App. I found pages.js.coffee in my javascript folder and I renamed it to pages.js

The part of a long paragraph that I need to hide in HTML I enclosed into div. And I added button "More" and gave it a class "click me" before that div element.

So my code in pages.js is below, but it does not work, what do I do wrong:

$(document).ready(function() {
    $(".hidetext").hide();
        $(".clickme").click(function() {
            $(".hidetext").show();
    });
});

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

It's a long shot, but maybe try using preventDefault upon clicking the button.

Well, I found this website js2cofee.org and converted my js code into js.coffee code. Then I renamed back my pages.js into pages.js.coffee and It works now. So my code in pages.js.coffee IS BELOW. Does anyone know why js is not compiling in this situation?

$(document).ready ->
  $(".hidetext").hide()
  $(".clickme").click ->
    $(".hidetext").show()
    return

  return