I am new to DOM manipulation in Angular 2. I am trying to modify a sibling element on the basis of attribute value on an element.
e.g. Adding asterisk (star) symbol on label, if input contains required attribute.
I am having a directive, which can access attributes, & form control on input field. Now I would like to modify sibling label from within this directive.
I am aware of nativeElement & Renderer2 basics, but unable to find proper way of accessing & modifying sibling.
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email" required validate>
</div>
in my validate directive I would like to check if required attribute is available on input, & if yes I would like to add a class on sibling element i.e. label.
I can access input element using ElementRef inside directive, but how to access & modify label or any other neighboring elements, i.e. child, parent, sibling.
Any reference document for such basic operations will be a great help.
@ViewChildand@ContentChildbindings to find aElementRefusing a#templateNamein the template. If you share some example code that would help give a formal answer. - ReactgularpreviousElementSiblingif you want to use jquery.prev - yurzui