Jose Alvin Rañola Jose Alvin Rañola - 1 year ago 147
jQuery Question

jQuery wrap with html comment tags

I already tried 3 solution but didn't work.

I want to wrap my sidebar with comment tags.

First solution:

$("#sidebar").wrap("<!--googleoff: index--><!--googleon: index>");

Second solution:

From this post: jQuery comment/uncomment <!--element-->

function comment(element){
element.wrap(function() {
return '<!--googleoff: index-->'+this.outerHTML+'"<!--googleon: index>';

Third solution:

$('#sidebar').prepend("<!--googleoff: index-->");
$('#sidebar').append("<!--googleon: index>");

the result I want:

<!--googleoff: index--> //start comment tags
<div id="sidebar"></div>
<!--googleon: index> // tags

Answer Source

Try this.

$('#sidebar').before("<!--googleoff: index-->");
$('#sidebar').after("<!--googleon: index-->");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download