How to get a html element by name

前端 未结 3 1983
盖世英雄少女心
盖世英雄少女心 2021-01-18 20:33

Is there a way in java script to get only a particular name instead of using document.getElementsByName(\"x\"); which return an array? I have a kind of special

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-18 21:13

    If you're looking for a single element, take the first one from the nodelist, for example:

    var element = document.getElementsByName("x")[0];
    

    You can test it out here.

提交回复
热议问题