NOTE: In the video, I am using text(), but I had to switch to html() for cross-browser compatibility.
As you can see from the video, the browser doesn't render the Script tags because they are script tags; but, at the same time, it doesn't error out because it's not trying to execute them as scripts either. This is quite brilliant and is blowing my mind a bit! The Type attribute of the Script tag is the mime type of the data contained within it. In my demonstration, I am using plain text, hence the "text/plain" type; but, you could change this to "application/json" as used by the metadata plugin for JSON data storage.
The first time I tried to do this, I use the .text() method to gather the data in the Script tag. This worked in Firefox, but not in Internet Explore. I changed it to use the .html() method and this seemed to work fine in FireFox, IE, Safari, and Chrome. And, as you saw in the video, when we run this example, we get the following output:
jQuery And Script Tags
* Plain text in script tag.
* More plain text in script tag.
This technique is definitely going to revolutionize the way I pass DOM meta-data via server-side XHTML.
Want to use code from this post? Check out the license.