views:

50

answers:

1

If there is a tag as <p id="name" onclick="javascript:var ele=context(this);">sumtext here</p><br>
<p id="name" onclick="javascript:var ele=context(this);">newtext here</p><br>

   <script>
    function context(obj)
     {
         var b = document.getelementbyID("area");
         b.removeChild(obj);
         //How to remove the preceeding element i.e,<br>
     }
   </script>

    <textarea id='area' rows="4" cols="70"></textarea>

<p> and <br> are not in a div and so if i remove <p> how to remove the preceding tag br from javascript

+2  A: 

You can use previousSibling() to find the, er... previous sibling of an element:

b.removeChild(obj.previousSibling());
b.removeChild(obj);  
Andy E