/    Sign up×
Community /Pin to ProfileBookmark

Disable all buttons and link (only) on a page

I know to disable all elements an a page with:

for(i=0;i<document.all.length;i++) document.all[i].disabled = true;

but I want to disable only buttons and links.

How I know that

document.all[i]

is a button or a link?

Thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@fredmvDec 22.2003 — Welcome to the forums.

Just so you know, the [font=courier]document.all[/font] collection is proprietary IE code. I'll assume this is for an intranet where you know what browsers your users are running. As for your question, you could do something like this:&lt;script type="text/javascript"&gt;
//&lt;![CDATA[
onload = function()
{
var all = document.all;

<i> </i> for(var i=0; i&lt;all.length; i++)
<i> </i> {
<i> </i> if(all[i].type.toLowerCase() == 'button')
<i> </i> {
<i> </i> // If it's a button...
<i> </i> }

<i> </i> if(all[i].tagName.toLowerCase() == 'a')
<i> </i> {
<i> </i> // If it's a link...
<i> </i> }
<i> </i> }
<i> </i>}
//]]&gt;
&lt;/script&gt;
Copy linkTweet thisAlerts:
@rosoft2001authorDec 23.2003 — the solution is to use document.forms[0].button object like:

document.forms[0].button[0].disabled = true;

Thanks
×

Success!

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