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

Marcelo Cortez
Marcelo Cortez
7,142 Points

Help - Build an Interactive Website > jQuery Plugins > Simple Email Validation Plugin (4/4)

Hey guys, I'm stuck at code challenge "Simple Email Validation Plugin" 4/4

The error msg displayed when I ask to 'check my work': "Bummer! null"

Challenge: "In the "success" function add the class of "valid" to the textarea that's had a the "keyup" event triggered"

This is what I'm trying:

  var isValid = $("input").validEmail(); 

  $("textarea").validEmail({on:"keyup", success:function(){
      $this.next().removeClass("error").addClass("valid");}, failure:function(){ 
        $this.next().removeClass("valid").addClass("error");}
  });

  requiredFilledIn();

Any help is welcome ^^

5 Answers

Marcelo Cortez
Marcelo Cortez
7,142 Points

Hi Andrew,

I tried and a new msg appeared: "Bummer! Try selecting 'this' in the success method and using the 'addClass' method"

So I tried some stuff and ended up with this:

var isValid = $("input").validEmail(); 

  $("textarea").validEmail({on:"keyup", success:function(){
      $(this).addClass("valid");}, failure:function(){ 
        $(this).next().removeClass("valid").addClass("error");}
  });

  requiredFilledIn();

That worked ^^

Thnx for the help!

I'm not sure how the .next() is supposed to be used. In the video lesson we use it apply the .addClass() and .removeClass() methods, but here you were able to pass the quiz by ommitting the .next() method?

It could be just me, but are addClass("valid"); and addClass("error"); not supposed to have the closing brackets at the end?

Marcelo Cortez
Marcelo Cortez
7,142 Points

The curly? They have...

"success:function(){ $this.next().removeClass("error").addClass("valid");}"

"failure:function(){ $this.next().removeClass("valid").addClass("error");}"