Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


JQuery remove previous element only if a button

JQuery remove previous element only if a button

JQuery remove previous element only if a button

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).


	<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>
		<div class="validation-summary-errors" data-valmsg-summary="true">
				<li>Invalid input</li>

So here I want to do something like:


previous = $("div[data-valmsg-summary]").prev()
if( previous.get(0).tagName == "BUTTON)

Is this the best way to do this?



RE: JQuery remove previous element only if a button

in jQuery the syntax would more be



fiddle here

RE: JQuery remove previous element only if a button

That is better.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close