pstein Posted June 20, 2015 Share Posted June 20, 2015 Assume I have HTML code similar to <div ...>....</div><hr><div ...>....</div>or <p>....</p><br><p>....</p> As you can see there are single <hr> or <br> elements with some leading or trailing whitespaces but no further textaround them.How can I delete them (including the leading/trailing whitespaces) but not the <div> resp. <p> elements before and after?Peter Link to comment Share on other sites More sharing options...
dsonesuk Posted June 20, 2015 Share Posted June 20, 2015 Use document.getElementsByTagName('HR'); (or ('BR') which will collect a list of these elements found, then you can identify the number '.length', create a for loop, and go through each one and remove. http://www.w3schools.com/js/js_htmldom_nodes.asp under removing existing html elements. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now