Exercise 14/16, Don't want to change text permanently


#1


https://www.codecademy.com/en/courses/learn-javascript/lessons/javascript-dom/exercises/text


I don't want to change my text permanently when clicked. I want to go back to my previous text when again clicked. So which code should I use?



#2

This lesson calls for a permanent change. Anything otherwise would require you to define a variable stating if it was opened or closed, and acting upon it as such, which you don't need to worry about for this lesson.


#3

I'm not worried. I just wanted to know how to do that. Can you please show me an example?


#4

Sorry for the late response. Here's one method you could use for this purpose:

var open = false;

function main() {
  $('.skillset').hide();
  $('.skillset').fadeIn(1000);
  $('.projects').hide();
  $('.projects-button').on('click', function(){
    //$(this).next().toggle();
    $(this).toggleClass('active');
    if (open){
      $(this).text('Recent Projects');
      open = false;
    }
    else{
      $(this).text('Projects Viewed');
      open=true;
    }
    $(this).next().slideToggle(400);
  });
}

$(document).ready(main);

#5

aha! cool! Thank dude!


#6

This topic was automatically closed after 7 days. New replies are no longer allowed.