1

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
  • 47,985
  • 13
  • 70
  • 91
yavg
  • 2,403
  • 5
  • 33
  • 82

6 Answers6

5

You need the Element.getAttribute() method:

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

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

Sujal Mandal
  • 923
  • 1
  • 13
  • 27
1

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

Have a good day!

Dongin Min
  • 309
  • 3
  • 4
  • 12
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
  • 6,189
  • 1
  • 26
  • 49
0

You can simply do with getAttribute:

console.log(element[0].getAttribute("validacion"));
Sajeetharan
  • 203,447
  • 57
  • 330
  • 376
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.