Questions tagged [replacewith]

JQuery .replaceWith() method. Replace each element in the set of matched elements with the provided new content and return the set of elements that was removed.

JQuery .replaceWith() method. Replace each element in the set of matched elements with the provided new content and return the set of elements that was removed.

The .replaceWith() method, like most jQuery methods, returns the jQuery object so that other methods can be chained onto it. However, it must be noted that the original jQuery object is returned. This object refers to the element that has been removed from the DOM, not the new element that has replaced it.

As of jQuery 1.4, .replaceWith() can also work on disconnected DOM nodes.

Source:http://api.jquery.com/replaceWith/

316 questions
3
votes
3 answers

jQuery wait for replaceWith to finish before executing

I bulk replace html in many divs with replaceWith. After replacing I am using jTruncate to truncate the texts. However it doesn't work, because at the time of execution, replaceWith is not done. I tried the callback trick (How do I extend jQuery's…
wizard
  • 145
  • 1
  • 14
3
votes
3 answers

replaceWith with jQuery Objects

I'm trying to use replaceWith(...) function with a jQuery Object but it does not work, when i try do it with inserted DOM elements it works, but not in jQuery objects. I have this: var obj = $('
Text
'); obj.replaceWith('New…
calbertts
  • 1,513
  • 2
  • 15
  • 34
3
votes
3 answers

Jquery replaceWith not working

Using Jquery 1.7.1 I have two divs
{page content here}
Those show up in the page source. But this jquery I added at the bottom of the page is not working:
Conando
  • 219
  • 1
  • 4
  • 16
2
votes
3 answers

Replace img with div jQuery

I'm looking to replace an image with a class to a div with text inside it, how can I do that? I know that code is screwed up, but it's just to…
henryaaron
  • 6,042
  • 20
  • 61
  • 80
2
votes
2 answers

jQuery replaceWith not keeping the link to the element in the DOM?

var el = $(this); // it's a form At some point: el.replaceWith('

Loading...

'); Later: el.replaceWith(output); Apparently el doesn't exist anymore after the first replaceWith... Can I keep somehow el, obviously with the new content ?
Alex
  • 66,732
  • 177
  • 439
  • 641
2
votes
2 answers

Section ID id is Visible in text with jquery replace function

I'm using the replace function to replace a div. Using something like this: $(document).ready(function() { $("#electricalengineering").click(function() { $("#section1").replaceWith("#section2"); }); });
Beck
  • 51
  • 6
2
votes
0 answers

.replace() causing site to flicker

I am using mongoose-paginate-v2 on the backend to paginate the response from my DB. I am trying to setup the front end to move through the data and send a request for the new data as needed. (That part seems to be working). The problem I am having…
2
votes
2 answers

How do I replace elements in an array?

I'm building a Wordpress site, where I've made it so that you can insert fullwidth images with parallax through the CKEditor by assigning the inserted images with a class. The script I've written replaces the found images with a div, and uses the…
2
votes
1 answer

ReplaceWith Conditional DTE

I want to match the terms "TextCtrls" and "LabelCtrls". When I find "TextCtrls" I want to replace with "Txt" and when I find "LabelControls" I want to replace with "Lbl". Online Demo Is this possible with DTE.Find.ReplaceWith? DTE.Find.FindWhat =…
2
votes
1 answer

Cannot read property 'replaceWith' of null - ajax call

I'm trying to replace "Hello world!" with "Hello to you too" using a ajax replaceWith. However I'm getting this error: Cannot read property 'replaceWith' of null Where am I taking the wrong turn? NOTE: the ajax call works with…
2
votes
0 answers

Angular Directive - replaceWith, ng-repeat and destroy

I have an array that is used for an ng-repeat. When this is updated, the directive is not currently not removed / destroyed from the DOM. The link function in the directive does a replaceWith replacing the element with a custom compiled element.…
Ewan
  • 378
  • 3
  • 14
2
votes
1 answer

replaceWith Jquery Not working if more than 2 images

I have a nav here with li inside is an anchor tag and span which consist of the text. What I want to achieve is to replace all span in the nav using jquery replaceWith however, I can't seem to make it work. This is the code I made. Any Idea what my…
icedev
  • 215
  • 1
  • 17
2
votes
2 answers

Replacing text with a checkbox using ReplaceWith

I'm having trouble replacing text with a div that includes a checkbox. When I have the following code, the text successfully gets replaced:

Hello

Hello

World