Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-02-2009, 03:31 AM   PM User | #1
lauthiamkok
Regular Coder

 
Join Date: Dec 2008
Posts: 117
Thanks: 14
Thanked 0 Times in 0 Posts
lauthiamkok is an unknown quantity at this point
jquery: to get image width on page ready

Hi,
How can I get the width of an image when the page is ready...?

I tried the code below, but it always return the value '0'...!

Code:
<script type="text/javascript" src="js/jquery/jquery-1.3.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	var width = $("#image img").width();
	alert(width);
});
</script>
PHP Code:
<div id="image">
<
img src="xxx.jpg" />
</
div
many thanks,
Lau
lauthiamkok is offline   Reply With Quote
Old 08-02-2009, 04:26 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,554
Thanks: 9
Thanked 480 Times in 463 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
ready fires before images load.
window.onload would work.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:15.2% IE7:0.5% IE8:8.4% IE9:8.5% IE10:8.5%
rnd me is offline   Reply With Quote
Old 08-02-2009, 05:29 PM   PM User | #3
lauthiamkok
Regular Coder

 
Join Date: Dec 2008
Posts: 117
Thanks: 14
Thanked 0 Times in 0 Posts
lauthiamkok is an unknown quantity at this point
Quote:
Originally Posted by rnd me View Post
ready fires before images load.
window.onload would work.
thanks, i got the answer now which is i need to put the size of the image in img tag so that javascript can pick up the value on page ready.

this is the page im working on. if u turn off javascript on your browser then u will see what i want to achieve to degrade the page gracefully when there is no javascript enabled.

http://lauthiamkok.net/tmp/projects/part/

thanks,
Lau
lauthiamkok is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:05 PM.


Advertisement
Log in to turn off these ads.