clears all the child divs, but leaves the master intact.
Use jQuery’s CSS selector syntax to select all div elements inside the element with id masterdiv. Then call empty() to clear the contents.
Using text('') or html('') will cause some string parsing to take place, which generally is a bad idea when working with the DOM. Try and use DOM manipulation methods that do not involve string representations of DOM objects wherever possible.
If all the divs inside that masterdiv needs to be cleared, it this.
else, you need to iterate on all the div children of #masterdiv, and check if the id starts with childdiv.