Reputation: 377
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
Reputation: 171
Your code is work fine, you forget the close the class of div 4...
Upvotes: 0
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
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