When you want to display code, you’re probably working with pre elements. The fact that they can contain markup make them really effective for syntax highlighting. I’ve used Knockout en comment binding to generate code into a pre field and that’s really cool.

Wouldn’t it be need if one could click on the element en it would select all its text? With a little bit of jQuery, it is done in a heartbeat:

$(document).on('click', 'pre', function () {

	if (this.select) {
		this.select();
	}
	else if (document.selection) {
		var range = document.body.createTextRange();
		range.moveToElementText(this);
		range.select();
	} else if (window.getSelection) {
		var range = document.createRange();
		range.selectNode(this);
		window.getSelection().addRange(range);
	}
});

Selectors
Just change the selector if you want to change the element on which it works. This also works for code and textarea.