0

What is the difference between name="" and id=""?

name= vs. id=

2nd Mar 2021, 7:43 AM
Pia S.
Pia S. - avatar
4 Answers
+ 3
ID is a Global Attribute and applies to virtually all elements in HTML. It is used to uniquely identify elements on the Web page, and its value is mostly accessed from the frontend (typically through JavaScript or jQuery). Name is an attribute that is useful to specific elements (such as form elements, etc) in HTML. Its value is mostly sent to the backend for processing.
2nd Mar 2021, 8:22 AM
Mr. Unknown
+ 1
Hey there Pia S., ID is used to identify the HTML element via ID, as the name says. We can then change this element by referring it via ID (ex. JavaScript (=> document.getElementById...) or CSS (=> #id {}... ). ID is expected to be unique. NAME correspond the a form (element) and identifies what we post to the server. Hope it helps :) Happy coding 🙂
2nd Mar 2021, 8:06 AM
Matthew
Matthew - avatar
+ 1
Hello, Id is a unique identifier of an HTML document. In CSS, the id attribute is referenced with the # character. In Javascript, it is referenced with getElementById().The name attribute defines the name of the element. the name attribute must begin with a letter and is case sensitive, but unlike the id attribute, it can be not unique.
2nd Mar 2021, 9:34 AM
AjayGohil
0
There should be only one element in the page with a certain ID. There can be as many elements with the same name if they don't exist in the same <form>. ID is selected in CSS with hashtag prefix. #idOfElem name is selected in CSS with attribute selector [name="nameOfElem"] When submitting a form, the request body object is indexed by the names of the input elements. The IDs are ignored. Elements with IDs are automatically hoisted to the JavaScript global object. Elements without ID are not hoisted.
2nd Mar 2021, 10:40 AM
Ore
Ore - avatar