jQuery - Selector for duplicate ID's

前端 未结 7 1206
名媛妹妹
名媛妹妹 2020-12-02 00:40

I have a page with duplicate ID\'s for a form element. The catch is I the elements show up separately based on a toggle. So both ID\'s never show up simultaneously.

7条回答
  •  借酒劲吻你
    2020-12-02 00:45

    as Rwwl said, duplicate IDs are invalid. Assign classes instead of ids to them.

    Then you can do

    alert($('.my_element:visible').val());
    

提交回复
热议问题