jQuery equivalent to “getElementsByName”

后端 未结 5 668
一生所求
一生所求 2020-12-25 14:07

What is the correct jquery syntax for a getElementsByName call?

Here is my javascript code:

var test = document.getElementsByName(tableN         


        
5条回答
  •  不思量自难忘°
    2020-12-25 14:55

    "[name=tableName]" is bad syntax in 2 ways. First, you should put your name in quotes, so it should be "[name='tableName']" and second, in the first case, you're using a variable and in the second, a string, so in reality it shoudl be "[name='" + tableName + "']"

    good call also on the fact that you have an index on your getelementsbyname() call, if you select item [0] then it will only return one item.

提交回复
热议问题