I have some invalidly-nested HTML like:
<form class="form1" method="get">
<div>
<input name="field1">
</form>
<form class="form2" method="get">
<input name="field1">
</form>
</div>
Yeah, it's a mess, don't ask. The invalid nesting is causing problems somewhere else. jQuery I think is expecting a closing </div>
, and only finding it at the last one. It's then treating the second <form>
tag as invalid, and also discarding the closing </form>
immediately above it, and assuming everything between lines 1 and 9 are one form.
If I output these to the console:
$('.form1).html()
- all of line 1 - 9$('.form2).html()
- undefined
So what I'm trying to do is treat the whole thing as a string, and use regex to strip out form2. I'm expecting a regex something like:
formText.replace(/(<form\b[^>]*>)[^<>]*(<\/form>)/gi, "");
but I'm not sure how to reference the specific form with class=form2
.
There's also a problem with it being a multi-line string.
Update: added more detail, outlining why jQuery's remove()
method isn't working. jQuery only thinks there's one form unfortunately.