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);
精彩评论