Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

quoting a string

I found a bit of code on the web that I would like to use.

$(document).ready(function() {
$(".fbreplace").html.replace(/<!-- FBML /g, "");
$(".fbreplace").html.replace(/ -->/g, "");
$(".fbreplace").style.display = "block";
});

The problem is the browser thinks

<!--

is a real comment. How would I quote it in a way to tell the browser look for that string and it is not a real comment?

like image 340
keith Avatar asked Jan 21 '23 12:01

keith


1 Answers

Escaping one of the symbols won't change the regular expression. You can use a backslash to prevent the browser from interpreting the -- as the start or end of an HTML comment:

/<!-\- FBML /g

Having said that, I don't know of any modern browser that would misinterpret a piece of Javascript as a comment if the Javascript is correctly enclosed in a <script> tag.

like image 180
Mark Byers Avatar answered Feb 03 '23 21:02

Mark Byers