JQuery dynamic id control property

So, I have jQuery dynamically generating controls. Input controls are called EnterLink + the number of generated controls. When generating a new input control, I want to modify a previously created input so that it is disabled. Now my code looks like this, but it does not work.

if (rowCount > 0) {
                   var last = rowCount - 1;
                  $("#EnterLink" + last).disabled = true;
                  }

It seems like it should work, I checked the identifiers of the controls and just like they are formatted.

+3
source share
2 answers

Replace this:

$("#EnterLink" + last).disabled = true;

Wherein:

$("#EnterLink" + last).attr('disabled', true);

jQuery DOM $(). , , - (, , , ), jQuery.

DOM #EnterLinkX, :

$("#EnterLink" + last)[0].disabled = true;

, $() , , . [0] ( ) . innerHTML . 99% , , "jQuery way", . attr , removeAttr, , - .

+10

, .

$( "# EnterLink" + ).attr( "disabled", true); $ ( "# EnterLink" + ).attr( "", "" );

+2

Source: https://habr.com/ru/post/1711867/


All Articles