0
jQuery('div#top').replaceWith('<div id="top">

</div>')

Chrome says uncaught syntaxerror unexpected token in the first line. I dont know whats the error here. I am just trying to replace the top div.

FYI -- I am replacing the whole data of div top with mine. I am placing a lot of div`s inside top which I havent pasted here.

1 Answers1

4

JavaScript strings can't span across multiple lines. You either have to add newline escape sequences:

jQuery('div#top').replaceWith('<div id="top">\n\n</div>')

Or add backslashes at the end of each line:

jQuery('div#top').replaceWith('<div id="top">\
\
</div>')

Or just use .html() (assuming you weren't trying to get rid of any attributes on that element):

jQuery('div#top').html('')

Or .empty():

jQuery('div#top').empty()
Blender
  • 289,723
  • 53
  • 439
  • 496