there are lots of ways in jQuery to create relationships between
selectors depending on your markup. Without seeing any markup it's hard
for anyone else to help you create those connections ProfCrazyHorse wrote: I want to replace one element with another, and keep the element contents intact. For example, here, I'm replacing all h2 elements with h3's:$("a #replaceWith").click(function () { var h2Text = $("h2").text(); $("h2").replaceWith("<h3>" + h2Text + "</h3>"); }); I have two questions. First, how can I do this more simply? I tried the following, but $ (this) refers to the anchor tag and not the h2 selector. Is there a way in jQuery to refer to the selector, i.e. $("h2")? $("a #replaceWith").click(function () { $("h2").replaceWith("<h3>" + $(this).text + "</h3>"); }); My second question: Is there a method more appropriate than replaceWith to replace certain elements on the apge with others? Thank you! |
- [jQuery] replaceWith() ProfCrazyHorse
- [jQuery] Re: replaceWith() Charlie
- [jQuery] Re: replaceWith() Cesar Sanz
- [jQuery] Re: replaceWith() mkmanning
- [jQuery] Re: replaceWith() ProfCrazyHorse