简体   繁体   中英

Angular get tag content inside a specific ID

I have an HTML template as follows:

<div id="expenses">
    <submenu>
    </submenu>
</div>

<div id="revenues">
    <submenu>
    </submenu>
</div>

I need to hold the submenu content in seperate variables. The following code works in angular:

var expenses = angular.element('#expenses')

However, I need to get one step further and get the submenu content in the variable. Something like:

var expenses = angular.element('#expenses>submenu')

But CSS selectors don't work in that function. How can I get the submenu contents?

您可以使用find()函数获取子元素。

    element.find("submenu")

您可以使用:

document.querySelector('#expenses > submenu');

也许:

var expenses = angular.element('#expenses').children()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM