Home · Examples

Reciprocal JavaScript

Have you ever needed to load a JavaScript based upon some JavaScript condition that was set to true, or some function that was run, or object that was called? (You get the idea)

Well, in some cases, you may just need to do just that. The primary focal point in doing this lies within JavaScript's createElement method. We can use this method to create a new script element to call another file from within the page.

First, lets create a variable named efile then we can assign this the value of that new script element.

var efile = document.createElement("script");
efile.src = "/path/to/myscript.js";
efile.type = "text/javascript";

The above JavaScript code is equivalent to this in HTML:

<script src="/path/to/myscript.js" type="text/javascript"></script>

Continue reading Comments (0) Apr 05, 2008

Conditional Selectors

You might be thinking "Conditional?–I thought CSS was static code." Well yes, true, it is static. But allow me to explain.

According to the W3C spec, CSS is supposed to obey laws of specificity. If one selector is more specific than another, it will get selected before the lesser specific ones. Or, if one rule has a higher precedence than another, it'll get selected instead of another with lower precedence (or importance). For example...

Lets say we wanted to have all of our <h1> elements to look bold, and be in the Verdana font, here is the CSS code we would use to do that:

h1 {
  font-family: Verdana;
  font-weight: bold;
}

Continue reading Comments (0) Aug 22, 2007

The invalid target attribute

For those of you who didn't know, the W3C has made the target attribute of the anchored hyperlink, invalid. Yes, therefore, we're not supposed to use it anymore.

The CSS-3 target-new property promises an alternative method for opening new windows, but full browser support for this may still be years ahead of us.

I usually do this to get around the validation error. It's probably not the best solution, but it works.

<a href="#" onclick="target='_blank';">new window</a>

Continue reading Comments (1) Aug 09, 2007

<< First < Previous [1 / 5] Next > Last >>