Text

Mar 17, 2010
@ 10:06 am
Permalink
1 note

Rambling about JS

Remember, you can attach actions to events by assigning an anonymous function to said event.

Before this, yes, I know, this is basic, but I’ve a post coming on the subject on my way of learning things. :D

Example: Let’s open up an image from a link, and preload the image before displaying it and using jQuery to display, because I’m lazy with vanilla JS;

var preload-image = new Image();
preload-image.onload = function() {
    var image = $("#image");
    image.attr("src", "goatse.jpg").show();
}
preload-image.src = "goatse.jpg";

We could probably add a delete statement to remove the unwanted and then unused image tag;

EDIT: Thanks for Antti S. for reminding me that you can’t delete variables declared with var, so instead just null it;

preload-image = null;
  1. fuckyeahgoatse reblogged this from piparkaq
  2. piparkaq posted this