CYBERSIX
CYBERSIX

Reputation: 377

Replace Div With Simple Jquery

I would like to be able to replace my div within each other but it s not working cant figure out why

$(function(){
    $('#4').replaceWith ('#2');
});

here is a the jsfiddle

Upvotes: 0

Views: 47

Answers (3)

Your code is work fine, you forget the close the class of div 4...

Upvotes: 0

invernomuto
invernomuto

Reputation: 10211

Its just a typo

change

<div class='short yellow id="4"'>

with

<div class='short yellow' id="4">

As @kao3991 already saw

replaceWith method needs an object in parameter, not a selector

so you have to change

$(function(){
        $('#4').replaceWith ('#2');
    });

with

$(function(){
    $('#4').replaceWith ($('#2'));
});

http://jsfiddle.net/62brm6o5/1/

Upvotes: 2

kao3991
kao3991

Reputation: 402

jquery replaceWith method needs an object in parameter, not a selector. So $('#2').replaceWith($('#4')); will work. And you've made a typo as InvernoMuto mentioned.

Upvotes: 1

Related Questions