Replace Name Attribute with Variable - JQUERY

2019-08-02 16:32发布

问题:

I am using a select element to change the search type on a media site (i.e. search by genre, search by artist).

I have created the dropdown and can get the selected option via a variable but now I need to replace the name attribute on the input element with the variable/selected option. I have seen the below code to change the "value", is there anything like this for changing the name attribute on an input element.

$("input[name$='letter']").val("a letter");

回答1:

.attr('name', 'blah')