3

I'm trying to get the "validacion" property of an HTML element.

console.log (element[0]);

This returns me:

enter image description here

<input class="estilo_input_text ng-pristine ng-untouched ng-valid ng-empty" id="asunto" name="asunto" ng-model="asunto" placeholder="Asunto" type="text" validacion="required">

How can I access the "validacion" property?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
yavg
  • 2,761
  • 7
  • 45
  • 115

6 Answers6

7

You need the Element.getAttribute() method:

console.log(element[0].getAttribute("validacion"));
2

Try element[0].attributes['validacion'].value

Have a good day!

Dongin Min
  • 409
  • 3
  • 5
  • 12
1

Use the element[0].getAttribute("attribute_name"); method.

Sujal Mandal
  • 975
  • 1
  • 14
  • 29
1

Don't know why you need to do this:

You'd better use the directive way to get the element.

Or you can use Angular jqLite API:

angular.element('#asunto').attr('validacion')
huan feng
  • 7,307
  • 2
  • 32
  • 56
0

You can simply do with getAttribute:

console.log(element[0].getAttribute("validacion"));
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
0

I think this is the answer you're looking for.

Since you're using Angular and you're implementing ng-model="asunto" why not make it like this in html.

<input class="estilo_input_text ng-pristine ng-untouched ng-valid ng-empty" id="asunto" name="asunto" ng-model="asunto" placeholder="Asunto" type="text">

<button ng-click="get_model(asunto)"></button>

In your JS:

$scope.asunto = "model";

$scope.get_model = function (string) {
  console.log(string)
}

I think this might work becuase you're already using ng-model why not use ng-model instead.