-1

I know you can change almost any attribute value of an HTML elements with JavaScript. The tricky one is the name attribute. Is it possible to change with JavaScript? I have read on the internet is a readonly attribute, and you may change in some browsers but not in others. Can anyone clarify me this matter?

Thanks!

1

2 Answers 2

0

You can

<input id="a" name="aName"/>
<script type="text/javascript">
        var a = document.getElementById('a');
        a.name = 'newName';
        alert(a.name);
</script>
Sign up to request clarification or add additional context in comments.

Comments

-1

You can use Jquery to change the name attribute in the following way

$("selector").attr('name', 'newName');

or using pure javascript you can use something like:

document.getElementById('someId').name = 'someName';

or alternately you can use the setAttribute() function too ,but please note its not supported in IE 8 and below.

the code will be something like this

document.getElementById('someId').setAttribute("name","someName");

Name attribute is not Read-Only, you can read the specifications here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.