Reputation: 23342
In my AngularJS directive, I want to apply focus to the first child of type <pre>
of the last child of type <div>
.
That is if my document looks like this:
<div main-div>
<div>
</div>
<div>
<div>
<pre></pre>
</div>
</div>
<div>
<div>
<pre the-one></pre>
</div>
</div>
the <pre>
it should select is the last one, with an attribute the-one
.
Is there any way to do this?
Upvotes: 2
Views: 6320
Reputation: 49590
if you have the structure above as a jqLite element (however you get it a hold of it), you could do the following:
var divs = element.children().find("div");
var theOne;
if (divs.length > 0){
theOne = angular.element(divs[divs.length-1]).find("pre");
}
Upvotes: 4