Reputation: 9
Here is my html code:
<div>
Please complete this form to create a new account.
<br>
Fields marked with (*) are required.
<div id="errorZone"></div>
</div>
I want to select text between div and div id="errorZone".
I'm trying this code:
$('#errorZone').prev().text().remove();
But this doesn't work
Upvotes: 0
Views: 176
Reputation: 97
may be you can use the .parent() instead of .prev(). See this link:- How to get the text of parent element using jquery?
Upvotes: 0
Reputation: 253506
If you want to remove everything (including the <br />
):
var start = document.getElementById('errorZone');
while (start.previousSibling) {
start.parentNode.removeChild(start.previousSibling);
}
var start = document.getElementById('errorZone');
while (start.previousSibling) {
start.parentNode.removeChild(start.previousSibling);
}
<div>
Please complete this form to create a new account.
<br>Fields marked with (*) are required.
<div id="errorZone">Text in 'errorZone.'</div>
</div>
Upvotes: 4