views:

96

answers:

1

I'm trying to select a particular set of div elements and change their height properties to auto. The jquery code I use to do that at the moment is:

$("div#TreeView1 td > div").css("height","auto");

Unfortunately I have to use the MS javascript lib (despite my protests). How can I do something similar using Microsoft's ASP.net AJAX?

+2  A: 

The direct translation for $("div#TreeView1 td > div").css("height", "auto") using the tools available in the ASP.NET AJAX framework would be:

var results = [];

// "#TreeView1 td"
var tds = $get('TreeView1').getElementsByTagName('td');

// would have just used Array.forEach here but
// MS borked it in debug mode for NodeList
for(var i=0, leni=tds.length; i < leni; i++) {
  var td = tds[i];
  // "td > div"
  for(var j=0, lenj=td.childNodes.length; j < lenj; j++) {
    var node = td.childNodes[j];
    if(node.nodeType === 1 && node.nodeName.toLowerCase() === 'div') {
      results.push(node)
    }
  }
}

// .css("height", "auto")
Array.forEach(results, function(element) {
  element.style.height = 'auto'
});

Now, ask your boss which one he/she would prefer to maintain. Seriously, go ask right now.

Crescent Fresh