How can I select an element by name with jQuery?

前端 未结 14 2777
迷失自我
迷失自我 2020-11-22 05:13

Have a table column I\'m trying to expand and hide:

jQuery seems to hide the td elements when I select it by class but not by element\'s name.

<
14条回答
  •  臣服心动
    2020-11-22 06:03

    You can get the name value from an input field using name element in jQuery by:

    var firstname = jQuery("#form1 input[name=firstname]").val(); //Returns ABCD
    var lastname = jQuery("#form1 input[name=lastname]").val(); //Returns XYZ 
    console.log(firstname);
    console.log(lastname);
    
    

提交回复
热议问题