jQuery Solution (slower, easier to implement)
If jQuery is required for other things in your site, and speed is not really a concern to you, here's the jQuery way to achieve the same result:
$("#slideshow li").width(w);
Non-jQuery solution (faster)
jQuery is significantly slower than simple javascript dom manipulation.
Create a simple library for javascript you need - reuse is good.
jQuery is a very large library for doing something so straightforward.
Note: Example uses namespacing. Encapsulation is better, but namespacing is a good start.
var myNS = {
elById: document.getElementById,
elsByParentId: function (id, optionalTagName) {
var tag = optionalTagName || "*";
return myNS.elByID(id).getElementsByTagName(tag);
}
setWidthForEls: function (els, w) {
for (var i=0, c=els.length; i < c; i++){
els[i].style.width = w;
},
getWidthOfEl: function (el){
return el.style.width;
}
setWidthForElsFromEl: function (els, el) {
myNS.setWidthForEls(els, myNS.getWidthOfEl(el));
}
}
Then, in the code section you are referring to, you just do:
myNS.setWidthForElsFromEl(
myNS.elsByParentID("slideshow","li"),
myN.elByID("content")
);