1
var elements = document.getElementsByClassName('active');
while(elements.length > 0){
    elements[0].classList.remove('active');
}
$event.target.classList.add('active');

It shows document not defined error

1 Answer 1

3

you're using web technologies in a native mobile application. The best way to get the id of the element is by giving your element a ref and doing something like this:

 const textField = this.$refs.groceryTextField.nativeView

There are lots of good examples in this repo: https://github.com/tralves/groceries-ns-vue/ and you can also checkout the marketplace for more code samples: market.nativescript.org.

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

2 Comments

How to add/remove css class to that ref ?
You could do this right in the markup of the template: :class="{'visible': elements.length > 0}"

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.