Muttalli
Muttalli

Reputation: 9

what's the default value of a name in tag of html

I have a pop-up modal in that their is p tag I have specified some id to it. and in javascript, I have written a code to perform some action based name on that. Since I haven't specified any name to the p tag I have using it in the JS file. but I don't how it is working. below is my HTML code and js code. does JS take default name as id value??

I have run this on VisualStudio (Asp.net)

<div class="modalbody">
<p id="alert"></p>
</div>

if(document.getElementsByName("alert")[0]!=undefined)
{
some actions
}

Upvotes: 0

Views: 210

Answers (1)

Sid Vishnoi
Sid Vishnoi

Reputation: 1318

From MDN Docs:

The getElementsByName method works differently in IE10 and below. There, getElementsByName() also returns elements that have an id attribute with the specified value. Be careful not to use the same string as both a name and an id.

Upvotes: 1

Related Questions