# Safe way to select the current ion-view element

**URL:** <https://forum.ionicframework.com/t/safe-way-to-select-the-current-ion-view-element/14035>\
**Category:** uncategorized\
**Created:** [December 12, 2014, 5:32pm UTC](https://forum.ionicframework.com/t/safe-way-to-select-the-current-ion-view-element/14035 "2014-12-12T17:32:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![felquis](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/felquis/32/64844_2.png) [@felquis](https://forum.ionicframework.com/u/felquis)\
**Post date:** [December 12, 2014, 5:32pm UTC](https://forum.ionicframework.com/t/safe-way-to-select-the-current-ion-view-element/14035/1 "2014-12-12T17:32:57Z")

</div>

Continuing the discussion from [Please help test: Angular 1.3, improved transitions, cached views (repost)](http://forum.ionicframework.com/t/please-help-test-angular-1-3-improved-transitions-cached-views-repost/13561):

When you use `document.querySelectorAll('span');` it will select all elements from all `ion-view`, the only way to detect the current view, is to use the `nav-view="active"` attribute.

```auto
var currentView = document.querySelector('ion-view[nav-view="active"]');

currentView.querySelectorAll('span'); // Spans tags from the current view only

```

Shouldn’t [$ionicHistory.currentView()](http://ionicframework.com/docs/nightly/api/service/%24ionicHistory/) give us the current view element?

Is `ion-view[nav-view="active"]` the only way to get the current view?

I’m afraid I’ll use `nav-view` attribute and in the future you change the values, attribute name or something else. Thanks.

---

<div class="post-metadata">

**Author:** ![felquis](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/felquis/32/64844_2.png) [@felquis](https://forum.ionicframework.com/u/felquis)\
**Post date:** [January 13, 2015, 5:27am UTC](https://forum.ionicframework.com/t/safe-way-to-select-the-current-ion-view-element/14035/2 "2015-01-13T05:27:22Z")

</div>

I created an issue [https://github.com/driftyco/ionic/issues/2920](https://github.com/driftyco/ionic/issues/2920)

---

<div class="post-metadata">

**Author:** ![mrwaim](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mrwaim/32/90909_2.png) [@mrwaim](https://forum.ionicframework.com/u/mrwaim)\
**Post date:** [August 7, 2015, 12:13am UTC](https://forum.ionicframework.com/t/safe-way-to-select-the-current-ion-view-element/14035/3 "2015-08-07T00:13:18Z")

</div>

> [@felquis](#):
>
> ion-view[nav-view=“active”]

I’m also looking for a solution, the above doesn’t work, in tabbed view.

---

<div class="post-metadata">

**Author:** ![mtoo020](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@mtoo020](https://forum.ionicframework.com/u/mtoo020)\
**Post date:** [February 18, 2016, 12:40am UTC](https://forum.ionicframework.com/t/safe-way-to-select-the-current-ion-view-element/14035/4 "2016-02-18T00:40:36Z")

</div>

> [@mrwaim](#):
>
> > [@felquis](#):
> >
> > ion-view[nav-view=“active”]
> 
> I’m also looking for a solution, the above doesn’t work, in tabbed view.

I’m using tabs and this works for me:

```
$scope.$on('$ionicView.enter', function () {
            angular.forEach(document.querySelectorAll("ion-view"), function (element) {
                if (element['$attr-nav-view'] == 'entering' || element['$attr-nav-view'] == 'active') {
                    console.log('element is the active view');
                }
            });
        });

```
