Html duplicated ID

后端 未结 8 1780
渐次进展
渐次进展 2020-12-01 23:41

My control is built dynamically accordingly to user input, there are n textboxes whose IDs are dynamic too.

However, I did not foresee that this HTML w

8条回答
  •  遥遥无期
    2020-12-02 00:25

    Even though is is wrong there is nothing wrong with the selector in jQuery

    $('#Container1 #TextBox1').val(1)
    $('#Container2 #TextBox1').val(2)
    

    Demo: Fiddle


    A better choice will be use attribute selector

    $('#Container1 input[id="TextBox1"]').val(1)
    $('#Container2 input[id="TextBox1"]').val(2)
    

    Demo: Fiddle

提交回复
热议问题