I am looking for script in AJAX who changes the dimensions of a DIV.
im try to find it in google but nothing... please help me!
I am looking for script in AJAX who changes the dimensions of a DIV.
im try to find it in google but nothing... please help me!
▐ Quieres Ganar $50 dólares totalmente gratis en menos de 24 horas? Visita este Post y ve como lograrlo
▐ http://x10hosting.com/forums/mercado/124800-gana-0-35-por-ser-mi-referido-unos-50-00-extra.html
There is nothing Ajax-y about resizing an element. Ajax, by definition, means making a background request to the server. All you need is plain old JavaScript.
(Yes, I happen to like banner-style indents. So sue me.) There are still holes in this code -- I usually use something similar to Protoype's $() to fetch the element(s) with more sophisticated type checking, default assumptions and iteration where necessary (as when a collection is returned). Don't "search the web" for scripts, since you will probably have to modify something you don't understand in order to make it work on your page -- learn the language.Code:function resizeElement(div, height, width) { elem = (typeof(div) == "string") ? document.getElementById(div) : div; if (!div || typeof(div) != "object") { return false; } div.style.height = height; div.style.width = width; return true; }
“Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
"It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)
essellar, correct me if I'm wrong (as I haven't touched JavaScript for a while), but concerning this part of the code:
... shouldn't div.style.height = height; be elem.style.height = height; instead, as elem has been assigned the object information and perhaps not div? The same applies for div.style.width= width;.HTML Code:elem = (typeof(div) == "string") ? document.getElementById(div) : div;
Last edited by smithee; 06-29-2010 at 04:44 PM.
.
“Be nice to nerds. Chances are you’ll end up working for one.” - Bill Gates
Actually, that's the result of an editing error (the posted code was excerpted from something else). Should have read:
Thanks for the sharp eyes -- but why would you change "div" to read "elem" in four places when changing "elem" to read "div" once would have done the same thing, and without introducing an unnecessary variable?Code:function resizeElement(div, height, width) { div = (typeof(div) == "string") ? document.getElementById(div) : div; if (!div || typeof(div) != "object") { return false; } div.style.height = height; div.style.width = width; return true; }
Last edited by essellar; 06-30-2010 at 08:38 AM.
“Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
"It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)
Yeah that's a good point, I suppose I've missed that whilst glancing over the provided code late last night.
@medina... What essellar has provided should be sufficient enough to meet your requirements; no Ajax here needed at all. If you run into any more trouble, just post another message and we'll be happy to help.
.
“Be nice to nerds. Chances are you’ll end up working for one.” - Bill Gates