How to get a html element by name

前端 未结 3 2076
盖世英雄少女心
盖世英雄少女心 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:17

    Or use jQuery, so you don't have to bother with all the browser annoyance.

    You just have to do this:

    $("*[name='x']").first();
    

    To get the first element with that name. If you know the element type than you can use it instead of "*". jQuery will make your life easier every time!

提交回复
热议问题