Friday, January 29, 2010

jQuery 1.4

The jQuery Javascript library, without which cross-browser Javascript development is unthinkable, has reached version 1.4.1.

Particularly useful is the ability to create new DOM elements. (See this brief discussion, though no anchor link means you'll have to search for "Quick Element Construction.")

What those docs overlook is the .text property, which enables you to create a proper element:

$("#foo").append( jQuery("<div>", {
id: "foo",
text: "I'm a new DIV element",
click: function() {
$(this).css("backgroundColor", "red");
}}));


or even create a nested elements via .html:
$("#foo").append( jQuery("<select>", {html: "<option value='1'>One</option>"}) );

4 comments:

Jake said...

Does this mean you've abandoned MochiKit?

kieran said...

You won that argument ;)

I still miss a couple MochiKit features, like the operator table, but jQuery very nearly transforms the language, and in a good way.

I'd still prefer Python, of course.

kieran said...

Oh, and MochiKit's interactive interpreter is still the bomb.

Jake said...

I like to use Firebug as my interactive interpreter. With it, you can develop using MochiKit, jQuery, or pure JS.