10

Jquery replaces inner div with another

 2 years ago
source link: https://www.codesd.com/item/jquery-replaces-inner-div-with-another.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Jquery replaces inner div with another

advertisements

I am trying to replace an nested div with a new div.

html_string= "<div id='container'><div id='inner'></div></div>";

var newHtml = $(html_string).find("div#inner").replaceWith("<div>NEW CONTENT</div>").html();

console.log('new html is');
console.log(newHtml);
console.log('html_string is');
console.log(html_string);

However I get an output of

new html is

html_string is
<div id='container'><div id='inner'></div></div>

It doesnt get replaced...


html_string= "<div id='container'><div id='inner'></div></div>";

var newHtml = $(html_string).find("div#inner").replaceWith("<div>NEW CONTENT</div>").end().get(0).outerHTML;

console.log('new html is');
console.log(newHtml);
console.log('html_string is');
console.log(html_string);

Demo: Fiddle

Related Articles

Replace a div with another on the hover

I want to replace one div with another when hovering over it. Specifically there will be an average in words, such as "struggling" or "exceeding expectations", and I want to replace this with the numerical average when the user hovers

.replaceWith () does not work when you replace a div with another after the click of the button

I am trying to replace a div with another to create a multipage app. I have a div with id = start which holds my form. The form needs to be replaced by the div with id = list when the button is clicked. The form is getting reloaded and I am not getti

How to replace a Div with another Div but only once

I am trying to replace a div with another div onclick using the code below. It works fine for one instance. However, the problem is when the class appear more than once which is the case for me (multiple instances)it obviously changes all instance as

Replacing a div with another - jquery

I have 4 divs and in each one there are top and down arrows. If user click top arrow - current div change place with higher div and conversely. How can I do this? This code is for "bottom arrow" and doesnt work... $("button.down").clic

I need to replace a div with another div using jQuery

<div id="main"> <div id="abc"> <div> This is the div to be replaced </div> </div> <div id="xyz" style="display:none"> <div> This is the div replaced </div> </div>

jQuery replaces one class with another

I have this jQuery and I'm changing styles in it but I've heard that the correct way to do it is to create a separate style and just replace classes with jQuery. Can you explain me how to do it correctly: $('.corpo_buttons_asia').click(function() { $

Replacing a div with another

Have 2 divs. Here is code <p style="text-align: center;"> <video id="preview" controls style="border: 1px solid rgb(15, 158, 238); height: 280px; width: 300px;" muted="muted" ;></video> </p>

how to replace a div [] with another div []?

for ($i=0; $i<10; $i++) { my $v1 = $sel->get_text("//body[\@id='ext-gen3']/div[10]/div[2]/div/div/div/div/div/div/div/div/div/div[2]/div/**div**/table/tbody/tr/td/div/div"); my $v2 = $sel->get_text("//body[@\id='ext-gen3']/div[10]/

Replace multiple DIVs with Jquery

I have a jquery script which replaces 1 div with another and replaces 1 link with another when it is selected: $('.child2, a[href="#1"]').hide() $('#replacepagelinks a').click(function(){ $(this).hide().siblings().show() var w = this.hash.replac

How do I replace a div with a widget when it is already contained in another widget?

I'm using Ext-GWT and I think ListView is the right layout for what I need. My problem is that I have to use a HTML template for all of my items, but I want to build GWT/Ext-GWT widgets instead, so I'm using div placeholders that I will replace with

The Bootstrap drop-down menu does not work when I replace a div with html by an ajax call

Here's my code <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="jumbotron" id="rkhs"> <h2 align="right" id="welcome">Welcome to RKHS Page</h

Is there a way to replace the class with another in Intellij Idea?

Guys, here is my problem: I have some class which is used in many places in my project. And I must replace this class with another from jar provided. Is there any ways to refactor this? I suppose this is a simple problem, but I dont know how to solve

Try to replace a fragment with another

I need to replace a fragment with another at an onItemClick method. This is what I am trying: public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TipoRestaurante rteActual = (TipoRestaurante) adapter.getItem(position);

How do I replace a JPanel with another JPanel in the same position?

I have a JFrame with about four frames. After a given action I want to replace one panel with another in the same position. My method for switching them looks like this (the this object is a class which extends JFrame): public void switchPanel(){ mai

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK