/    Sign up×
Community /Pin to ProfileBookmark

using javascript variables

hello, i am a newbie and i have a simple question, i hope you get to help me. thanks! here is my question:

my html code looks like this:
<tr id = 5>
<th> hello </th>
</tr>

now i want to access “hello” using javascript such that i get to underline it and this is what i do:

var refRow = document.getElementById (“5”)
var cell = refRow.cells
cell[0].innerHTML = “<u>cell[0].innerText</u>”

but this doesn’t work, even if I assign cell[0].innerText to a variable such that i have:

var cellText = cell[0].innerText
cell[0].innerHTML = “<u>cellText</u>”

how do i do this? underline “hello”? thanks very much!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@QuerelJun 24.2006 — You need to put a semicolom(';') after every line in javascript. Also, innerText is not supported in firefox, the text will change in 'undefined'.

You can use the script below:
<i>
</i>function changeText() {
var refRow = document.getElementById ("5");
var cell = refRow.cells;
cell[0].innerHTML = "&lt;u&gt;" + cell[0].innerHTML + "&lt;/u&gt;";
}


It has as disadvantage though that when you execute it multiple times, there will be multiple <u> tags around the orginal element.
Copy linkTweet thisAlerts:
@FangJun 24.2006 — <u> is [URL=http://www.w3.org/TR/html4/present/graphics.html#edef-U]depreciated[/URL], use [I]style[/I].

[I]Id[/I] must not begin with a number: http://www.w3.org/TR/REC-html40/types.html#type-name

The array is rows[] not row[]
&lt;tr id ="row5"&gt;
&lt;th&gt; hello &lt;/th&gt;
.
.
document.getElementById ('row5').cells[0].style.textDecoration='underline';
Copy linkTweet thisAlerts:
@felgallJun 24.2006 — Further info:

innerText doesn't work on all major browsers and so should be avoided. It can't be used to insert tags anyway, just text.

innerHTML does work for all major browsers but has some limitations such as not being able to be used across table cells in some browsers.

<u> is deprecated, assets are depreciated.
×

Success!

Help @superchritch 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.8,
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,
)...