0

I'm doing some DOM manipulation by adding function on click event inside my directive.

Basically it's animation of moving 4 little boxes to right and showing 4 "new" boxes sliding from left side. For real that's just 20 boxes in line with hidden overflow that you can see only 4 at time and on click it's just adding margin-left: -270px to pretend horizontal scrolling.

Currently I'm "catching" this 20 elements with

document.querySelectorAll(".last-added-element").forEach(function(elem) {

and this solution is working fine untill I use my directive twice at same page (same view). It's then scrolling boxes in both direcrives when I execute function.

Can I somehow scope above line (querySelectorAll method) to get NodeList of results but only from its template no entire DOM?

1 Answer 1

1

link in directive exposes element the directive is called on so query from that element

link:function(scope, element, attrs){
   // element is a jQlite object
   element[0].querySelector('.someClass').doSomething 
}
Sign up to request clarification or add additional context in comments.

3 Comments

but it's restrict: 'E', directive it's not called on some html element it's more like component: <horizontal-elements></horizontal-elements>.
doesn't make any difference. Th <horizontal-elements> element is still element in link arguments
You could add that I can't use getElementById with el[0] only querySelector and querySelectorAll. :D But anyay this answer is efficient, thanks!

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.