2

Html

<input type="text" class="fulltextbox saving_field" dataid="1" dataname="temperature" dataunit="&deg; F" ng-model="addVt.Temp.value" />

js

    var tData = [];
angular.forEach(angSel('.saving_field'), function(v, k){
            console.log(v.dataname);
            tData.push({id: v.dataid, name: v.dataname, value: v.value, unit: v.dataunit});
    });

But I am getting v.dataname as undefined.

1 Answer 1

2

You should be using the following attribute to access it:

v.dataset

Also, the data attributes should have a hyphen in them. Like data-name and not dataname.

So HTML would be:

<input type="text" class="fulltextbox saving_field" data-id="1" data-name="temperature" data-unit="&deg; F" ng-model="addVt.Temp.value" />

And in Javascript:

tData.push({id: v.dataset.id, name: v.dataset.name, value: v.value, unit: v.dataset.unit});

See the documentation on how to properly use data attributes.

Sign up to request clarification or add additional context in comments.

4 Comments

and to get the value of its "class" attribute ? v.class gave undefined. v.dataset.class gave undefined.
You can generally use getAttribute javascriptkit.com/dhtmltutors/domattribute.shtml
or className for class specifically.
Thank you @nandeep mali for the answer and the link. It is very useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.