JavaScript script tag in a JavaScript String?

That error has nothing to do with your attempt to inject a tag. The error "$ is not defined" means exactly that, "$" is undefined, it doesn't exist, thus you can not invoke it via $().

Up vote 1 down vote favorite share g+ share fb share tw.

I have the same issue as here: Script tag in JavaScript string However I can not resolve the issue with the proposed solutions. I'm using datatables plugin for jquery. I tried different solutions from above thread but none work.

I get a "$ is not defined" error. If I set var html to like "test" it works fine. The script in the String inserts a ActiveX control (IE) or plugin (FF) and displays data from database.

In below code the var html somehow breaks the script: function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { var dataURL = "'data:chemical/smiles," + aData0 + "'"; var html = '' + 'cd_insertObject("chemical/x-daylight-smiles", 182, 172,' + '"CDCtrl' + iDisplayIndexFull + '","","True","False","True",' + 'dataurl='+ dataURL + ');'; $('td:eq(0)', nRow). Html(html); // here $ causes an error return nRow; } Note that I also tried to escape all also in the opening script tag. Same issue.

Any ideas how to solve? EDIT: Found solution but can't answer my own question so here it is: jQuerys .html() function strips away script tags. I found that in the comments the documentation for .html().

Another issue is that the 3rd party function cd_insertObject uses document.write(). My solution was to copy+paste cd_insertObject but instead of using document write I return a string and then I put this string in $('td:eq(0)', nRow). Html(html); javascript string script-tag link|improve this question edited Jun 1 '11 at 11:19 asked Jun 1 '11 at 8:26beginner_566 58% accept rate.

That error has nothing to do with your attempt to inject a tag. The error "$ is not defined" means exactly that, "$" is undefined, it doesn't exist, thus you can not invoke it via $() The likely cause is that you included this script before you have included jQuery, move the jQuery script tag above the one that loads this script to fix it. It's also possible that you've used jQuery.noConflict(), causing $ to no longer refer to jQuery.

Another possibility is that in between including jQuery and this code there is code that redefines $ to undefined: $ = undefined.

Jquery is loaded first. If I comment out 'var html' and write $('td:eq(0)', nRow). Html('test'); it works fine.

I also don't use jquery. Noconflict or $ = undefined. How could I re-define $?

– beginner_ Jun 1 '11 at 9:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions