JQuery .replaceWith() html element to div class
问题 I want to replace <div class="blog">Blog</h1> with <h1>Blog</h1> which is inside a class name "sidebar" I used this code but didn't work: $(window).load(function() { $( ".sidebar h1" ).replaceWith( "<div class="blog">Blog</h1>" ); } What is wrong on my code? 回答1: If you want double quotes within a string that is delimited by double quotes, you must escape them with a backslash: "<div class=\"blog\">Blog</h1>" Many programmers use single quotes for JavaScript strings, which makes it easier to