/    Sign up×
Community /Pin to ProfileBookmark

Obtaining <TD> cell width in a javascript when using "%" of screen option

I have looked through the JavaScript Goodies book and have found how to reference the size of a <IMG> tag. I want to grab the width/height of a percentage defined table/cell and then take that value to define the picture length. I am trying to have the images resize when the browser/table resizes. But, I am having difficulty obtaining the actual value that is assigned. I have named the cell and used document.cellname to try to reference it to no avail. Any suggestions?

Thanks,
Ken

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@khalidali63Dec 29.2002 — Method below will worj for both NS6+ and IE5+ browsers

<body >

<table id="myTable" width="50%" height="50%" border="2">

<tr>

<td width="30%" height="30%" align="center">&nbsp;</td>

<td width="40%" height="30%" align="center">&nbsp;</td>

<td width="30%" height="30%" align="center">&nbsp;</td>

</tr>

<tr>

<td width="30%" height="40%" align="center">&nbsp;</td>

<td width="40%" height="40%" align="center">&nbsp;</td>

<td width="30%" height="40%" align="center">&nbsp;</td>

</tr>

<tr>

<td width="30%" height="30%" align="center">&nbsp;</td>

<td width="40%" height="30%" align="center">&nbsp;</td>

<td width="30%" height="30%" align="center">&nbsp;</td>

</tr>

</table>

<script>

onload = parseHTML

function parseHTML(){

var tds = document.getElementsByTagName("td");

for(x=0;x<tds.length;x++){

var td = tds.item(x);

var width = td.width

var nw = width.substring(0,width.indexOf("%"));

nw = (parseInt(nw)+10+"%");

td.setAttribute("width",nw);

}

}

</script>

</body>

Khalid
×

Success!

Help @schaferkj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...