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

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! :)