开发者

Remove preceding tag

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 preceding 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?


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

b.removeChild(obj.previousSibling());
b.removeChild(obj);  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜