kamal
kamal

Reputation: 237

remove one child and select another one

I have this html code:

<div id="step-1st">
  <pre style="display:none"></pre>
  <textarea></textarea>
</div>

I like to remove textarea and show the pre with the below code:

$("#step-1st textarea").remove().parent().children("pre").show();

Surely this can be done easily with more than on line, but i want to know how to do so with one line.

Upvotes: 0

Views: 71

Answers (3)

Blake Plumb
Blake Plumb

Reputation: 7199

This should do it.

$("#step-1st pre").next().remove().end().show();

FIDDLE

There are many ways to do it, but you are most likely going to need to use .end() to get back to the original selector.

Upvotes: 1

A. Wolff
A. Wolff

Reputation: 74420

if you have more than one <pre> elements:

$("#step-1st textarea").parent().children("pre").show().end().end().remove();

Upvotes: 1

jk.
jk.

Reputation: 14435

$("#step-1st textarea").prev("pre").show().end().remove();

http://jsfiddle.net/q3cMn/

Upvotes: 1

Related Questions