Question

I have several text boxes with attribute 'readonly'

@Html.TextBoxFor(model => model.ClientNumber, new {@readonly = "readonly", @class ="message-label"})

How can I find all of them using jQuery (to enable similar behavior on keydown event)?

Was it helpful?

Solution 2

well use attribute seletor..

 $('input[readonly="readonly"]').keydown(function(){
     .....
 });

or just

$('input[readonly]').keydown(function(){..});

OTHER TIPS

Try:

 $('input[type="textbox"][readonly]').on('keydown', someHandler);

or shorter:

 $(':text[readonly]').on('keydown', someHandler); //less performance effective than the previous one.

Also if you have a container that holds these and you know the container seelctor then this would be much faster.

 $('containerSelector').find('input[type="textbox"][readonly]').on('keydown', someHandler);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top