Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

Detecting Value of Generic Custom Attribute Without Adding Code Directly to Element?

I'm trying to figure out, using Javascript, how to detect the value of an email input by using the last attribute "aria-invalid" (will equal "true" or "false"). The issue is other fields on the page use the same attribute "aria-invalid" in the same fashion. Not sure how I can read the value of the email input attribute only? I can NOT add any code to the element and NO jQuery please.

<input class="masked-zip-code not-empty input-validation-error" data-val="true" data-val-regex="Enter a valid (5-digit) ZIP code." data-val-regex-pattern="^\d{5}(-\d{4})?$" data-val-required="Enter a ZIP code" id="ZipCode" name="ZipCode" type="text" value="" aria-required="true" aria-describedby="ZipCode-error" aria-invalid="true">

Open in new window


Thanks!
ASKER CERTIFIED SOLUTION
Avatar of MJ
MJ
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Julian Hansen
As a matter of interest - why no jQuery?

You can do it like this if you are not worried about older versions of IE

var x = document.querySelectorAll('[aria-invalid="true"]');

Open in new window

Avatar of MJ

ASKER

HI JUlian,
NO jQuery because this will be part of a DTM rule which gets deployed to multiple third-party solutions which may not have jQuery?
Avatar of MJ

ASKER

Found answer on my own
The accepted answer does not answer the question.
I'm trying to figure out, using Javascript, how to detect the value of an email input by using the last attribute "aria-invalid"
The solution uses an id of ZipCode on the element to find the attribute - but this has no bearing on the question.
No email field and nothing to say this is the last field with aria-invalid attribute.

Cannot see how the accepted solution asks the question asked.