0

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

1
  • try this : $('#errorZone').parent().remove('br').text(); Commented Dec 31, 2014 at 9:33

3 Answers 3

4

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>

Sign up to request clarification or add additional context in comments.

2 Comments

This what I'm looking for.I want to remove text including br.Thank you.I appreciated your help.
You're very welcome indeed, I'm glad to have helped! :)
0
$('#errorZone').closest('div:not('.errorZone')').remove(); 

2 Comments

Try this one. may be this will help you. in mean while i am trying to find out a better option for you.
You are a great team :)
0

may be you can use the .parent() instead of .prev(). See this link:- How to get the text of parent element using jquery?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.