Tags and Attributes

by Nick Jensen on October 6, 2013

Here I go on the second chapter of JavaScript: A Beginner’s Guide. So far this book is running hot and cold. Some of the learning instructions are below the level of “no duh”. For instance, the author begins chapter two by telling me how to open and close a script using the opening (<script>) and closing (</script) tags. I know this is just the beginning of the book, but isn’t the reader already supposed to be familiar with tags? If the author himself asserts that basic knowledge of HTML is a prerequisite to learning JavaScript, then why spend an entire page on opening and closing tags. I don’t need him to lecture me on case sensitive tags. I already learned enough about that when I began reading about HTML. Enough, already! Let’s move on, shall we? Well, at least the next bit of info is helpful.

According to the author, John Pollock (I guess it wouldn’t sound right if I addressed him as “the author” throughout the entire blog), there are six <script> tag attributes. The first script attribute is “type”. The “type” attribute is used to tell the browser which type of script is being used. Though, according to Pollock, the “type” attribute is often left out because most browsers use the JavaScript scripting language (that sounded redundant) by default. The “language” and “charset” attributes are for the most part, obsolete. The “src” attribute, on the other hand, is quite helpful. It allows you to enter external scripts (those from external files) into an existing script, which in turn saves you the hassle of manually typing the script into any area in which it’s needed. I guess it works in a similar manner to a CSS (Cascade Style Sheet). But what of the last two attributes, “defer” and “async”? Well, both of them deal with loading external scripts at a specified time. Something tells me I’m getting closer to fixing that accursed video file. For those of you who don’t know what I’m raving on about, see my last blog entry.

There is one last vital piece of information on chapter two. As I mentioned earlier, the “src” attribute allows you to enter scripts from an external file. Pollock states that JavaScript coders often use external scripts to speed up the process of coding a web page. Let’s say you wrote you a very long script. Manually writing each script into each separate HTML file would prove to be ridiculously tedious. However, you can easily bypass the problem by referencing the file in which the script is stored. The code itself would appear as <script type=”text/javascript” src=”example.js”> where example.js is the name of the file. Remember, though. The external script must always be saved in the same folder where your HTML document resides. Otherwise, the script that you reference will not appear. Well that wraps it up for chapter two. If you want to learn more about JavaScript, make sure to read my next upcoming blog on chapter three.

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: