I need to remove the previous element only if it is a button. And then I need to unwrap div I am looking at (but only if the previous element was a button that I just deleted - if not don't do anything).
So here I want to do something like:
Is this the best way to do this?
Thanks
Tom
Code:
<div>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert">
<span aria-hidden="true">×</span><span class="sr-only">Close</span>
</button>
<div class="validation-summary-errors" data-valmsg-summary="true">
<ul>
<li>Invalid input</li>
</ul>
</div>
</div>
</div>
So here I want to do something like:
Code:
previous = $("div[data-valmsg-summary]").prev()
if( previous.get(0).tagName == "BUTTON)
{
$("div[data-valmsg-summary]").prev().remove()
$("div[data-valmsg-summary]").unwrap()
}
Is this the best way to do this?
Thanks
Tom