开发者

Remove preceding tag

开发者 https://www.devze.com 2022-12-23 13:47 出处:网络
If there is a tag as <p id=\"name\" onclick=\"javascript:var ele=context(this);\">sumtext here</p><br>

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

精彩评论

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