Sorry if this is not the best place to post this problem. Basically In my editor once a user selects a paragraph and selects from a style from a list, it is sent to the function f which calls document.ExecCommand('formatblock', false,'<h1>'). If the user selects the same text again and selects a diff heading style then instead of removing the prev h1 tag it wraps the whole paragraph with h2 tag. so it looks like <h2><h1> text </h1></h2> var myElem = document.getElementById(MyControls[myArea]); // my area is the textarea myElem.focus(); if (myControl.selectedIndex==1){ // user selected H1 myElem.document.execCommand('formatblock', false, '<h1>'); }else if (myControl.selectedIndex==2{ // User seletced H2 myElem.document.execCommand("RemoveFormat"); myElem.document.execCommand('formatblock', false, '<h2>'); } You guys know how to fix this? I have been stuck on it for ages. Any help will be much appreciated.