jquery textbox attribute selector

maqskywalker
maqskywalker used Ask the Experts™
on
I'm using jquery.
I have 3 textboxes on my page.
They are named. textbox1, textbox2, textbox3

Right now I have this  run on page load:

// disable first dom element whose id starts with textbox
$('[id^=textbox]')[0].disabled = true;

But since I used [0]. That only disables the first textbox.

How do i revise the above line to disable all elements whose id starts with textbox ?
So it should disable all 3 textboxes.

Or if it would be easier by Class.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Team Lead
Commented:
try this:

$('input[id^="textbox"]').prop("disabled", true);

Open in new window

Top Expert 2010
Commented:
A class would be cleaner.

$('.myClass').prop('disabled', true);

Open in new window


Fiddle Demo:  https://jsfiddle.net/zephyr_hex/fbgvjt8a/

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial