Thursday, 15 September 2011

jquery - Determine width of an element -



jquery - Determine width of an element -

i have element need move screen when button clicked, , off screen when clicking again.

the problem not write specific width of box because not going same. thought code should it, i'm getting referenceerror saying "can't find variable: width". ideas how improve it?

var itemwidth = $("#about_box").css(width); console.log($("#about_box").width()); var itemout = false; $(document).ready(function() { $("#about").click(function(){ var value1 = 30; var value2 = -itemwidth; console.log(itemout); if (itemout == false) { $("#about_box").stop(); $("#about_box").animate({left: value1}, 350); itemout= true; } else { $("#about_box").stop() $("#about_box").animate({left: value2}, 150); itemout = false; } }); });

you should utilize 1 of these options:

$("#about_box").width() //element width $("#about_box").innerwidth() //element + padding width $("#about_box").outerwidth() //element + padding + border width

and utilize within $(document).ready handler, since before won't width dom not rendered yet.

jquery html

No comments:

Post a Comment