I have a div with the id of \"secondHeader\" and I want to replace that entire div with another div with the same id of \"secondHeader\" but instead of replacing it , it jus
Final Answer:
$.fn.loadWith = function(u){var c=$(this);$.get(u,function(d){c.replaceWith(d);});};
$("#test").loadWith("somelink.html");
jQuery load adds the response INTO the element selected. jQuery's replaceWith REPLACES the selected element.
start
$("#curElement").load("somelink.html");
will result in:
What ever was in somelink.html
$("#curElement").replaceWith("somelink.html");
will result in:
What ever was in somelink.html
I suggest adding a function to jQuery that does both:
$.fn.loadWith = function(u){
var c=$(this);
$.get(u,function(d){
c.replaceWith(d);
});
};
$("#test").loadWith("somelink.html");