0

I have a table with user interaction controls in its cells (button, link, etc.) and I want to "grayed" some rows of that table so all operations of these rows will be disabled.

Any idea what's the best way to do this in Javascript?

Abhinav Parashar
  • 475
  • 4
  • 9
  • 25

1 Answers1

0

Using jQuery, this sets the disabled property on <input> and <button> tags, which disables them:

$("#row_id input, #row_id button").prop('disabled', true);

Where row_id is the id of the row that has controls you want to disable.

For links, this makes it so that when they are clicked, nothing will happen:

$("#row_id a").click( function (e) {
    e.preventDefault();
} );

You probably also want to add some classes to them so you can style them differently. Just ask if you want to know how to do that.

There is a related question on disabling links at jQuery disable a link

Community
  • 1
  • 1
Nigel B. Peck
  • 5,804
  • 2
  • 16
  • 38
  • I can not use Jquery. – Abhinav Parashar Sep 12 '13 at 09:55
  • That's a shame, any particular reason why not? Perhaps we can help you find a way to be able to use it? It can be contained so it does not affect other code on the page. The reason is that with variations in web browsers' implementations of JavaScript, it is much more difficult to create robust code that works on all browsers. jQuery takes care of all that, and also simplifies the code itself. – Nigel B. Peck Sep 12 '13 at 09:59
  • we are already using YUI, and use of jquery will not be Approved by Lead. :( – Abhinav Parashar Sep 12 '13 at 10:51
  • 1
    Ah, ok. Well do it with YUI then :-) I don't know it, but the disable method was easily found on the website: http://yuilibrary.com/yui/docs/api/classes/ButtonCore.html#method_disable There is a YUI tag on here, perhaps add that to your question? http://stackoverflow.com/questions/tagged/yui You don't have to use jQuery, there are plenty of libraries out there. The main thing is to use one! Unless you want to spend a lot more time writing code than you need to! – Nigel B. Peck Sep 12 '13 at 11:05