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."

^^good advice


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -