Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

can anyone explain me this function i m really stuck here

var editpost = function(){
   var liItems = this.parentNode;
   var textarea = liItems.querySelector('textarea');
   var para = liItems.querySelector('p');
   var button = liItems.querySelector('button.btn1');

   var iscontain = liItems.classList.contains("editMode");

   if (iscontain) {
      para.innerText = textarea.value;    
      button.innerText = "EDIT";
      }else{
     textarea.value = para.innerText;
     button.innerText = "DONE";
   }
   liItems.classList.toggle("editMode");
}

//event handler
var edit = button.querySelector('button.btn1'); 
   edit.onclick = editpost;

1 Answer

Scott Callaway
Scott Callaway
13,311 Points

I'll put it into pseudo code to hopefully make it easier to understand.

IF the contents of 'iscontain' includes the phrase "editMode" THEN
   Set the text of the paragraph to the value of the textarea
   The text on the button is set to the String 'EDIT'
ELSE
   The value of the textarea is set to the contents of the paragraph
   The text on the button is set to the String 'DONE'
END IF

Change the boolean of the class name for the liItems element

Hope this is what you were looking for! :)