使用AngularJS获取没有id或class属性的子元素(Get child element without id or class attributes with AngularJS)

编程入门 行业动态 更新时间:2024-10-28 12:17:48
使用AngularJS获取没有id或class属性的子元素(Get child element without id or class attributes with AngularJS)

我有以下HTML代码:

<div id="someId"> <div ng-transclude> </div> </div>

真的很简单我使用以下函数获取具有ID属性的div元素:

var getElementById = function (id) { return angular.element("#" + id); };

在这个例子中,ID是'someId'。 我的目标是将div放在我刚刚得到的那个里面。 所以我想用ng-transclude属性返回div。 我相信这会通过按属性名称或其他东西获取元素来实现。

提前致谢。

PS:我不能在我想要的div中添加任何其他属性(比如id)因为在现实生活中它更加复杂并且代码是自动生成的。

I have the following HTML code :

<div id="someId"> <div ng-transclude> </div> </div>

Really simple I am getting the div element which has ID attribute using the following function :

var getElementById = function (id) { return angular.element("#" + id); };

Where in this example case the ID is 'someId'. My goal is to get the div inside the one I just got. So I want to return the div with ng-transclude attribute. I believe that this will happen by getting an element by attribute name or something.

Thanks in advance.

PS: I can't put any other attributes in the div I wanted(like id) because in the real life it is far more complecated and the code is auto-generated.

最满意答案

我想这会对你有所帮助

var getElementByAttribute = function (attribute) { return angular.element(document).find('[' + attribute + ']'); }; var el = getElementByAttribute('ng-transclude')

I think this will help you

var getElementByAttribute = function (attribute) { return angular.element(document).find('[' + attribute + ']'); }; var el = getElementByAttribute('ng-transclude')

更多推荐

本文发布于:2023-08-05 19:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1439492.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   元素   class   AngularJS   id

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!