/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Change Item label and class

I have an item that is hiding the label when created (see below). I want to dynamically change the label value and make it displayed. How do I do that?

<th class=”t12header” id=”CHECK$01″><label for=”x01″ class=”hideMe508″>Check All</label><input type=”checkbox” name=”x02″ value=”1″ onclick=”checkAll(this)” /></th>

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@savvykmsDec 07.2007 — Look up these functions and properties:

document.getElementById("IDOFHTMLELEMENT").innerHTML

document.getElementById("IDOFHTMLELEMENT").innerText

document.getElementById("IDOFHTMLELEMENT").className

(or is it .style.className?)

document.getElementById("IDOFHTMLELEMENT").style.display

document.getElementById("IDOFHTMLELEMENT").style.visibility

For example:

<th class="t12header" id="CHECK$01"><label for="x01" class="hideMe508" id="myid">Check All</label><input type="checkbox" name="x02" value="1" onclick="checkAll(this); document.getElementById('myid').innerHTML = '<b>my text</b>'; document.getElementById('myid').style.display = 'block';" /></th>
Copy linkTweet thisAlerts:
@Declan1991Dec 09.2007 — That is very deprecated and obstrusive, so try for some unobtrusive Javascript and use the W3C DOM.

Then run this function to show it.
[code=php]
function whateverYouWant() {
var l = document.getElementById("CHECK$01").getElementsByTagName("label")[0];
l.appendChild(document.createTextNode("My Text"));
l.style.display="block";
}
[/code]

Then look up,

document.getElementById

document.getElementsByTagName

document.createElement

document.insertBefore

document.appendChild

document.createTextNode.

Also, look up unobstrusive Javascript, and don't use IE only (even though they are pretty universally supported) methods like, innerHTML, outerHTML, innerText, outerText.
Copy linkTweet thisAlerts:
@FangDec 09.2007 — [I]id[/I] has illegal value
Copy linkTweet thisAlerts:
@rmaganauthorDec 10.2007 — Thanks. This did change it, but it appened the new label to the old label. I need to replace the old label. ie. it shows as 'OldLabelDel'.

How do I do that?


var l = document.getElementById("CHECK$01").getElementsByTagName("label")[0];

l.appendChild(document.createTextNode("Del"));

l.style.display="block";




That is very deprecated and obstrusive, so try for some unobtrusive Javascript and use the W3C DOM.

Then run this function to show it.
[code=php]
function whateverYouWant() {
var l = document.getElementById("CHECK$01").getElementsByTagName("label")[0];
l.appendChild(document.createTextNode("My Text"));
l.style.display="block";
}
[/code]

Then look up,

document.getElementById

document.getElementsByTagName

document.createElement

document.insertBefore

document.appendChild

document.createTextNode.

Also, look up unobstrusive Javascript, and don't use IE only (even though they are pretty universally supported) methods like, innerHTML, outerHTML, innerText, outerText.[/QUOTE]
Copy linkTweet thisAlerts:
@FangDec 10.2007 — function whateverYouWant() {
var l = document.getElementById("[COLOR="Red"]CHECK01[/COLOR]").getElementsByTagName("label")[0];
l.firstChild.data="My Text";
l.style.display="block";
}
Copy linkTweet thisAlerts:
@rmaganauthorDec 10.2007 — perfect
function whateverYouWant() {
var l = document.getElementById("[COLOR="Red"]CHECK01[/COLOR]").getElementsByTagName("label")[0];
l.firstChild.data="My Text";
l.style.display="block";
}
[/QUOTE]
×

Success!

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