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 -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -