LINQED.NET

This blog is about .NET and related technologies
By Vlad Azarkhin

February 2009 - Posts

Great video explaining the current financial crisis

The Crisis of Credit Visualized from Jonathan Jarvis on Vimeo.
To Tweet or not to Tweet? That is the question.

I own a Tweeter account for a very long time, however, haven’t used it a lot. I’m actually still trying to understand what is it good for. Well, I now know what Yosi is eating for his lunch, and a lot of other fun but useless stuff (no offence, Yosi, you know how much I admire you :)). But what else? How can I actually benefit from it?

Meanwhile, my account is http://twitter.com/vladaz. You’re invited to follow me. Who knows, maybe I’ll write something useful…

The Dark Side of my IDE

Following Pini’s post about his experience with dark IDE, I’m offering mine. Actually, my IDE is on a dark side for some time. I’ve experimented with

many different fonts, sizes and colors and came out with something that allows me to stay productive with minimal eye fatigue for long time.

Here is the sample from my code screen:

DarkIDE

The settings file is attached.

Enjoy

Extracting Text from DOM Elements – the jQuery way

Ken Egozi has posted a nice sample for extracting all the text from all the children of a particular element. I’m not sure why does one needs such a function, but it is a very good practice in Javascript.

The trick is to check each of the element children’s nodeType and if it is TEXT_NODE (3), take it’s nodeValue.

As a huge fan of a jQuery library, I’ve decided to do this sample using jQuery. Here it is:

function extractFirstLevelTextFrom(elm) {
var text;
$(elm).children().each(function() { text
+= $(this).text(); });
return text;
}

This function can accept not only DOM elements, but any jQuery valid selector. However, in case the selector results numerous elements, only the first one will be handled. It is possible to handle every selected element by altering the code to something like that:

$(elm).each(function(){$(this).children()…. });

The .children() method of the jQuery object returns all the immediate children, end .each() method loops on every child. It is important to notice that the current context of the .each() method (this) is the DOM element, not the jQuery object, so we’re getting the jQuery object simply by selecting the DOM element. Also, .each() method accepts delegate as an argument. Here I’ve chosen to use the anonymous one.

The .text() method returns and empty string in case the element doesn’t have an innerText property, so there is no need to check the element type.