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
0
votes
4 answers

What is the correct syntax for concatenating strings within jquery replaceWith

I have the following html markup
...lots of stuff
I need to replace this with a coffeescript function to give the following markup
Andy Harvey
  • 12,333
  • 17
  • 93
  • 185
0
votes
1 answer

Can't get jQuery replacewith "img to figure" to be link (a href) sensitive (breaks)

after much research via Google and having read several stackoverflow posts, having tinkered with my jsfiddle for hours, I have hit a brick wall. Appreciate any pointers or help! First Stackoverflow post myself here - hope I get this right. I love…
koala
  • 3
  • 2
0
votes
3 answers

Is there a way to attach a callback from one element to another in jQuery?

I have, for example this: $first = $('#firstElement').click(function() { }); But in some point of the execution of the page, I will replace that element with another: $newElement = jQuery('
'); $first.replaceWith($newElement); But I want to…
Cito
  • 1,659
  • 3
  • 22
  • 49
0
votes
1 answer

JQuery .replaceWith() suddenly putting new element in the wrong place?

This one is really baffling me. I'm using replaceWith() to "clear" a file input field. However, when it replaces it, it puts it back in the wrong place, and I have no idea why. I used the term "suddenly" in the title because what's even more…
vertigoelectric
  • 1,307
  • 4
  • 17
  • 37
0
votes
2 answers

.removeClass not functioning within .replaceWith

I'm trying to make a button that will hide a specific -- and then replace it with another hidden . However, when I test the code, everything fires correctly except for the .removeClass which contains the "display: none." Here is the code:
Darthfuzzy
  • 31
  • 1
  • 7
0
votes
1 answer
I've been trying to figure this out for several hours without much luck.. I'll ask my specific question first, but then give you the bigger picture after in case my entire approach is wrong. Specific Question: I'm trying to replace a list item…
0
votes
2 answers

jQuery replaceWith and toggle conflict

I have the html
I'm trying to replace span with a and use the anchor to .toggle()
$('#2').replaceWith(function(){ return $("
gavsiu
  • 757
  • 5
  • 9
  • 27
0
votes
4 answers

Fade out one table and replace with another using jquery?

I've found a few similar topics here searching but I've not been able to adapt them to my exact situation. I have a simple single page website (well, I want it to be a single page) with five hyperlinks near the top. I have five different tables to…
Simon K
  • 83
  • 1
  • 11
0
votes
4 answers

jQuery to replace contents of a
  • I have a link that wired up to a jQuery function. It is inside an
  • with another link. Code here:
  • 1testpdf.pdf
    ItsPronounced
    • 5,475
    • 13
    • 47
    • 86
  • 0
    votes
    1 answer

    replaceWith and textarea select

    Is it possible to assign select() to a replaceWith()? $('#foo').one('click', function() { $(this).replaceWith(''); }); $('#copy').click(function() { $(this).select(); }); I've tried the above code…
    Anna Riekic
    • 728
    • 1
    • 13
    • 30
    0
    votes
    1 answer

    using .replaceWith with switch function

    $(".td").click(function() { switch (elementNode.previousSibling.id) { case "location" (".td").replaceWith(''); break; case "occ" (".td").replaceWith('
    Hikaru Kagi
    • 5
    • 1
    • 6
    0
    votes
    1 answer

    how to use jquery 'replaceWith' twice in a document?

    i am trying to activate a jQuery 'replaceWith' function on click to replace div1 with div2 and then use 'replaceWith' again to replace div2 with div1 on click. everything is working except, when clicking on div2, div1 does not re-appear. my code…
    user1063287
    • 10,265
    • 25
    • 122
    • 218
    0
    votes
    2 answers

    jquery replaceWith implications

    I am using replaceWith for input type=file to handle changes of the file the user wants to upload. I have this code: $('#add_cv_input').change(function() { // here is some code else { alert('put one of this: pdf doc…
    vlio20
    • 8,955
    • 18
    • 95
    • 180
    0
    votes
    1 answer

    Ajax replaceWith using jQuery-rails

    I have a page that has two forms on it. Each form is a different way of filtering the results on the page. The first form is a collection_select. The second form is a text_field_tag. Each submits to the same controller and returns data using…
    Denise Mauldin
    • 5,397
    • 5
    • 32
    • 51
    0
    votes
    3 answers

    How to use replaceWith jQuery?

    I need to do two steps: 1)Show InputBox when clicking a div . 2)Showing the div back when mouse is out of that inputbox. step #2 does not work. a