0

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
  • 46,994
  • 13
  • 63
  • 85
yavg
  • 2,123
  • 2
  • 25
  • 65

6 Answers6

3

You need the Element.getAttribute() method:

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

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

Have a good day!

Dongin Min
  • 249
  • 4
  • 11
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
  • 5,307
  • 1
  • 22
  • 40
0

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

Sujal Mandal
  • 851
  • 1
  • 12
  • 25
0

You can simply do with getAttribute:

console.log(element[0].getAttribute("validacion"));
Sajeetharan
  • 186,121
  • 54
  • 283
  • 331
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.