javascript - Unexpected token < destroys other site functions -
i'm getting error line of code
jquery("body").html(jquery("body").html().replace(/some text/gi, "<strong>some text</strong>"));
i trying attach strong tag every instance of words "some text" across site pages.
but error destroys other site functionalities, ajax stuff.
error: uncaught syntaxerror: unexpected token < further info on error: (anonymous function) @ (index):227
this happens because function in body
tag.
when this...
<body> $(function(){ jquery("body").html(jquery("body").html().replace(/some text/gi, "<strong>some text</strong>")); }); </body>
you replacing instances of 'some text' in whole body including function itself
you could, move function head tag...
but @vohuman pointed out
"you shouldn't replace whole contents of body element. that's madness. select target elements , replace contents of specific elements."
Comments
Post a Comment